TL;DR: Custom fonts couldn't be used programmatically before using them in a Storyboard/xib.
Note: I've checked out this, tried the answers and they didn't work. I've also made sure that they're in target membership.
I've noticed a strange bug while changing segment control title a custom font:
segmentedControl.titleTextAttributes = NSDictionary(objects: [UIFont.init(name: "Comfortaa-Regular",
size: UIFont.systemFontSize)!,
UIColor.white],
forKeys: [NSAttributedStringKey.font as NSCopying,
NSAttributedStringKey.foregroundColor as NSCopying]) as? [AnyHashable : Any]
It couldn't find the font, so unwrapping has failed. But the font could be seen in the Storyboard.
It's properly added to the project, here's the CopyBundle and InfoList:
So here's the catch; if I use it in the Storyboard, it is shown in the font families:
But if not, it's not shown -here I've changed to light and bold has disappeared-, and cannot be used programmatically.
I'm using Xcode Version 9.0 (9A235), and Swift 4. I've also checked OpenRadar and couldn't find a submission regarding this.
The mentioned font: Comfortaa
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…