Custom Font Sizing in Xcode 6 Size Classes Not Working Properly with Custom Fonts

Autolayout does not use size classes when using a custom font

This is a size class bug. Custom fonts do not work with size classes. The best approach I've found is to use a UILabel subclass to replace the font and use the system fonts in IB.

Check out this answer for possible solutions: Custom Font Sizing in XCode6 Size Classes Not Working Properly w/ Custom Fonts

Note: I'm away from my computer right now but I'll post some sample code when I get back.

Custom Font not working with size class

Use the below code:

class MyCustomLabel: UILabel {
override func layoutSubviews() {
self.font = UIFont.init(name: “YourCustomFont", size: self.font.pointSize)
}
}
  1. Now Just Change the font from storyboard from your current font to System Font. And select whatever font size you want to use.

Sample Image

Actually self.font.pointSize :- This will help you fetching the font size from the Storyboard (whatever you have set with System font.)


  1. Just change the label class , and use MyCustomLabel in storyboard.
    Now run the application you will be able to see the changes.

Sample Image

Subclass UITextField to override font when using size classes with custom font

Well this turned out to be a really weird bug. It does work provided there is an element on your storyboard that is not set to System font, but is set to your custom font.

My fix was to put in an invisible label that was not using my subclass but set to the custom font in Interface Builder. Now all my other fonts, which are set to System in Interface Builder, are overridden in my custom classes correctly.

Thanks, Apple!

Custom Fonts in XCode 6 not being loaded onto the simulator

Make sure your fonts copied to bundle when project compiled. To check that open Build Phases tab of you project settings. Inside Copy Bundle Resources section check if your fonts listed. If not press plus button and add them.



Related Topics



Leave a reply



Submit