There are a few posts on this, but none seem to have a complete solution.
Using adaptive layout via IB I can easily change font sizes for specific size classes, however I have a custom view using UILabels and I want to programmatically set the font size depending on the size class in use (using swift) - Has anyone else had this issue or come across a solution?
You need your custom view to override traitCollectionDidChange(previousTraitCollection: UITraitCollection?)
from the UITraitEnvironment Protocol that UIView conforms to.
Discussion
The system calls this method when the iOS interface environment changes. Implement this method in view controllers and views, according to your app’s needs, to respond to such changes. For example, you might adjust the layout of the subviews of a view controller when an iPhone is rotated from portrait to landscape orientation. The default implementation of this method is empty.
You may have to observe height/width for the iPad size class: Regular| Regular
Your custom view (UIView) has a traitCollection
property that has the size classes
information. Check out the answer here https://stackoverflow.com/a/25795175/2503640
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With