System font renders as Times New Roman on iOS 13

Viewed 2796

I have some UILabel with the default system font. But when I install my app on iPad or iPhone with iOS 13.1 the fonts change to something like Times New Roman! Why does this happen? I am sure the label's text is Plain and the font is System. How can I fix this issue?

PS: I have downloaded all SF fonts from Apple web site, and still no luck!

3 Answers

I found the solution, the problem comes with detecting the current label's font. I changed:

descriptions.font = UIFont(name: (descriptions.font?.fontName)!, size: 22)

to

descriptions.font = UIFont.systemFont(ofSize: 22)

and problem solved.

Use UIFontDescriptor

I was having the same issue on iOS 13. Fixed it by using fontDescriptor instead of fontName. I have UILabel in my storyboard connected to its view controller via IBOutlet with font as Text Styles - Callout.

@IBOutlet weak var lblText: UILabel!

Below one didn't worked as expected and showing Times New Roman font:

let font = UIFont.init(name: lblText.font.fontName, size: 50.0)!
lblText.font = font
lblText.text = "Times Coding :)"

Solution using UIFontDescriptor:

let font = UIFont.init(descriptor: lblText.font.fontDescriptor, size: 50.0)
lblText.font = font
lblText.text = "Times Coding :)"

This way it will pick the font you set to a label in your storyboard, you don't need to hardcode the font name.

It seems like Apple is pushing to use the initializer with the weightage. Passing it with the name seems to break it ".SFUI-Regular".

The workaround for this is to use the function with weight like this : UIFont(systemFont:UIFont.systemFontSize, weight: .regular).

Related