Trying to implement support for Dynamic Type and have an issue. I set the style I want to use on a label or something in Interface Builder. I register for the UIContentSizeCategoryDidChangeNotification, and in the handler, I set the label's font to ... what? How do I know what style to use? Shouldn't there be an accessor that lets me find that out? If not, I have to put it in 2 places, which means they'll get out of sync and I'll be annoyed. Any thoughts?
iOS - Dynamic Type and Interface Builder
462 Views Asked by MacsimusPrime At
2
There are 2 best solutions below
0

I don’t think this will satisfy you, but set the font to [UIFont preferredFontForTextStyle:UIFontTextStyleTitle2
or whatever style you set in Interface Builder.
Ignore the setting in Interface Builder. It’s not even worth setting. Interface Builder is a (mostly) static representation of the initial state of your views, but this is Dynamic Type.
You could subclass UILabel
to make it dynamic, and/or join us on the dark side of setting up views in code.
Since iOS 10, there's no need to follow this rationale because the
adjustsFontForContentSizeCategory
property allows an automatic scaling of the font sizes according to the content type size selected in the settings.All the text styles are well defined in the Apple reference site and their size variations as well.