UILabel with a custom font scaled using UIFontMetrics sometimes fails to reflect changes to Dynamic Type size

Originator:argentumko
Number:rdar://33211585 Date Originated:July 10 2017
Status:Closed Resolved:Yes
Product:UIKit Product Version:
Classification: Reproducible:
 
Summary:
Setting UILabel's font to a non-scaled, non-text style font, and then setting it to a scaled version of that same font created using UIFontMetrics API causes the label to fail to update the rendered font if the Dynamic Type font size is then changed by the user – but only if the initial Dynamic Type font size (the one that was active when the label has been configured) was the default ("large"). This is an unexpected behaviour.

Steps to Reproduce:
1. Create a simple iOS app.
2. Somewhere in the code that configures the view hierarchy, create a UILabel with adjustsFontForContentSizeCategory property set to true.
3. Set that label's initial font to a custom, non-scaled font – e.g. system font 16pt, medium weight.
4. Afterwards, before or after adding this label into the view hierarchy, create a scaled version of *that same* initial font using a UIFontMetrics object. Change the label's font to this scaled font.
5. Make sure that simulator's/device's Dynamic Type font size is set to default ("large") and launch the app.
6. After launching the app, change the Dynamic Type font size to a lower or higher setting using Accessibility Inspector or Settings app. Return to the app if necessary.

Expected Results:
The label reflects the new Dynamic Type setting by rendering the scaled version of the font correctly.

Observed Results:
Label's rendered font stays the same as before Dynamic Type size has been changed.

Version:
iOS 11.0 (15A5304f)

Notes:
This issue is not reproduced in either of these cases:
* The initial Dynamic Type font size is not the default.
* Label's font is set to a scaled version of the custom font from the beginning – not to a non-scaled version first.
* Label's font is set to any unrelated font before changing it to a scaled font – maybe this makes the label invalidate its internal state? Could be caused by a font equality test?

The last condition can be used as a workaround for this issue. Note that this issue does not affect UITextField and UITextView.

The attached project demonstrates the issue.

Comments

As of iOS 13.5, this issue is fixed.

By argentumko at June 5, 2020, 10:17 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!