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)
}
}
- Now Just Change the font from storyboard from your current font to System Font. And select whatever font size you want to use.
Actually self.font.pointSize :- This will help you fetching the font size from the Storyboard (whatever you have set with System font.)
- Just change the label class , and use MyCustomLabel in storyboard.
Now run the application you will be able to see the changes.
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
Looping Through Nsattributedstring Attributes to Increase Font Size
What Is Sandbox in iOS? How to Transfer Data Between One App to Another App
How to Add Line Break for Uilabel
Uitableview Dynamic Cell Heights Only Correct After Some Scrolling
Why Push Notifications Is Not Working on Testflight
How to Compare Two Nsdate Objects in Objective C
iOS Game Center: Scores Not Showing on Leaderboard in Sandbox
Open Uitableview Edit Action Buttons Programmatically
How to Debug "Terminated Due to Memory Error"
Resize Textfield Based on Content
How to Use a Custom Font with Dynamic Text Sizes in iOS7
Use Didselectrowatindexpath or Prepareforsegue Method for Uitableview
What Is Prefix.Pch File in Xcode
How to Prompt the User to Turn on Location Services After User Has Denied Their Use