Dynamic Type on iOS7 backward compatible with iOS6

I am trying to configure Dynamic Type in my application, which should be compatible with 6.1+. I am using preferredFontForTextStyle: and it obviously crashes on iOS <7.0

How do you deal with this? respondsToSelector: and splitting by two font settings?

Is there a better way?

Thanks in advance!

+4
source share
2 answers

You can fend off UIFont dynamically only if the iOS version is less than 7.

What needs to be done to fix an unused method:

  • Prepare your own replacement for an unused method.
  • Check the OS version - "responsesToSelector:" is a great way to check it.
  • Add an implementation if the method does not exist.

In UI7Kit, I fixed it with addClassMethodForSelector: ... which is provided by FoundationExtension.

See: https://github.com/youknowone/UI7Kit/commit/701c44a69406ad971794c9ab46aeb0cfac1fa207#L3R57

This code adds a new preferredFontForTextStyle: method from an existing implementation of the __preferredFontForTextStyle method:

In addition, UI7Kit is starting to support the method right now. (still very rude) Try it if you want.

+2
source

I thought about it; probably the best way to do this is to manually add the preferredFontForTextStyle: method to the UIFont class at runtime if the application is running on iOS 6 and then dynamically selects the appropriate system font size. The UI7Kit project on github does something similar for other methods, but not unfortunately.

+1
source

All Articles