iOS Swift: maximumContentSizeCategory not working on UILabel

852 views Asked by At

According to this article:

https://useyourloaf.com/blog/restricting-dynamic-type-sizes/

And this WWDC 2021 video:

https://developer.apple.com/videos/play/wwdc2021/10059/?time=879

The minimumContentSizeCategory and maximumContentSizeCategory can limit the min and max font size when user uplevel/downlevel the font sizes in System Accessibility settings.

However I tried it out, and from the debugging info these two settings are properly set, but in view rendering, the font size still goes to very large if accessibility font size is very large.

 // before setting
 print(label.appliedContentSizeCategoryLimitsDescription)

 label.minimumContentSizeCategory = .small
 label.maximumContentSizeCategory = .accessibilityMedium

 // after setting
 print(label.appliedContentSizeCategoryLimitsDescription)

print results:

  1. UILabel:0x7fd610a414a0: AX-L --> AX-L

  2. UILabel:0x7fd610a414a0: S <= (none->)AX-M <= AX-M --> AX-M

How can I properly use these two settings?

1

There are 1 answers

0
XLE_22 On

Any ideas on how to properly use these two settings?

I hope that's the proper way because I use them as you did (and it works).

I created a blank project in Interface Builder (Xcode 13.4.1) as follows:

enter image description here

... and the Dynamic Type feature is blocked within the specified thresholds I defined like you (in the viewDidLoad of the view controller).

I think you should check out the way you created your label because, with the above one, it works like a charm.