System font renders as Times New Roman on iOS 13 - ios

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!

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

What is the system font of iOS13?

What is the iOS 13 system font?
Before iOS 13 I used SFUIDisplay font.
UIFont(name: ".SFUIDisplay-Light", size: UIFont.systemFontSize)
But on iOS 13 it doesn't work.
This bug is so BS. The only way to get around it is by using the systemFont(ofSize:weight:) method directly. AKA, you cannot get the system font using the method UIFont(name:size:), you ll just get Times New Roman for some funny reason. Apple devs must be messing with us. So for the original question above you must use the following:
UIFont(systemFont:UIFont.systemFontSize, weight: .light)
For my situation, I ran into this bug making an extension for UIFont to return the same font in a different size, which must work with custom and system fonts. In order for it to work on xcode 11 ios 13, I had to add a silly check to see if fontName contains ".SF".
extension UIFont {
func forSize(_ pointSize: CGFloat) -> UIFont {
if !fontName.contains(".SF"), let font = UIFont(name: fontName, size: pointSize) {
return font
}
return UIFont.systemFont(ofSize: pointSize, weight: weight)
}
}
If you are aiming to use the system font, you don't really have to worry about its name, you should let the system to do it for you.
let font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
At this point, whenever the system font changes, it will automatically updated.
Moreover
I use a lot of custom fonts. I need to do it
Actually, you could do it without mentioning the font name in case you want to use the system font. For example, you could implement a function that returns the proper font as:
func getFont(name: String = "", size: CGFloat = UIFont.systemFontSize) -> UIFont {
// system font
let defaultFont = UIFont.systemFont(ofSize: UIFont.systemFontSize)
if name.isEmpty {
return defaultFont
}
return UIFont(name: name, size: size) ?? defaultFont
}
For using the system font, call it: getFont(). Otherwise, call it with mentioning the name of the font: getFont(name: ".SFUIDisplay-Light").
However, you might think of doing something like this to get the system font name and then use it:
let systemFontName = UIFont.systemFont(ofSize: UIFont.systemFontSize).fontName
getFont(name: systemFontName)
I'd say it's meaningless since the UIFont.systemFont automatically detects the system font name without the need of mentioning it.
font-family: ".SFCompactText-Regular"; font-weight: normal; font-style: normal
It's "San Francisco (SF) Pro and Compact" font. You can check here https://developer.apple.com/fonts/
Create a font using systemFont(ofSize: CGFloat) -> UIFont.
Then get the fontName and familyName of that font.
Print the above and you have the answer for the current iOS; so run it on iOS 13.

Font in iOS11 is incorrectly displayed

I have a font called Poppins-bold (you can find it on Google Font) that in iOS 11 display incorrectly. Here you can see a screenshot with iOS 10:
And screenshot in iOS 11:
Four fonts displayed are:
Poppins Bold with a Storyboard
Helvetica Bold with a Storyboard
Poppins Regular via code
Poppins Bold via code
And my error is with Poppins Bold via code. My code is:
label1.font = UIFont(name: "Poppins-Regular", size: 30)
label2.font = UIFont(name: "Poppins", size: 30)
How is it possible?
I've printed font in the projects and this is my result:
Font Family Name = [Poppins]
Font Names = [["Poppins-Regular", "Poppins"]]
Your printout explains the problem. "Poppins" is a family name. If you have both Poppins Regular and Poppins Bold, the family name defaults to meaning the regular font. This prevents you from accessing the Poppins Bold font by its name, which (unfortunately) is "Poppins".
Instead, use the font descriptor to change Poppins Regular to Poppins Bold:
let font = UIFont(name: "Poppins-Regular", size: 30)!
let desc = font.fontDescriptor
let desc2 = desc.withSymbolicTraits(.traitBold)!
let font2 = UIFont(descriptor: desc2, size: 0)
self.lab.font = font2
I might be a bit late, but in case your question is still relevant, problem can be solved by updating font files from https://fonts.google.com/specimen/Poppins. You will also need to use "Poppins-Bold" font name instead of "Poppins".

UIFont.monospacedDigitSystemFontOfSize() not really monospaced?

I wanted to use SF's monospaced digits font to display an integer number in a text field by changing its font as follows:
textField.font = UIFont.monospacedDigitSystemFont(textField.font!.pointSize, weight: UIFont.Weight.semibold)
But if I set the text of the text field in a 60Hz frequency, this is the result:
The width of the text is clearly not constant for a same amount of digits so it is moving all jittery because the text field is constrained to "leading" and "trailing" of the image underneath.
Why is this the case and how to fix it?
Another truly monospaced font like "Menlo" is behaving correctly:
So it seems like setting the "adjust to fit" option of the text field is overwriting the monospaced property of the font (even if the view is big enough to contain the text!)
My temporary solution at this point is to
Set textField.adjustsFontSizeToFitWidth to false
Set the monospaced font again (as it was somehow overwritten by adjustsFontSizeToFitWidth's setter)
Begin to change the text
When finished set textField.adjustsFontSizeToFitWidth to true again in order to correctly behave on user input
This is not what I originally wanted but it works as a workaround
I have a project that uses the "adjust to fit" option and if I set the monospaced property using didSet for the label outlet, it seems to work for me in Xcode 8 Beta 3.
#IBOutlet weak var textLabel: UILabel! {
didSet {
textLabel = UIFont.monospacedDigitSystemFont(ofSize: textLabel!.pointSize, weight: UIFontWeightRegular)
}
}
In my case, I was setting the font property of a UILabel to a monospaced digit font and using attributedText to set the text. This worked in iOS 9 but broke in iOS 10. The workaround is to explicitly set the font attribute in the attributed string.
I was having the same problem and did set code worked. Updated for Swift 4:
#IBOutlet weak var textLabel: UILabel! {
didSet {
label.font = UIFont.monospacedDigitSystemFont(ofSize: textLabel!.font!.pointSize, weight: UIFont.Weight.regular)
}
}

Changing UINavigationBar Font Type while keeping the default size

I know that for changing the font of UINavigationBar he will simply do
self.navigationController!.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "MavenProBold", size: 15)!, NSForegroundColorAttributeName: UIColor.whiteColor()]
Tho, i'm trying to change only the font type, and keeping iOS default font size(which i guess he is dynamic among the devices).
Any suggestions?
If you change the font type, you will have to specify a font size. Generally you have to do this manually.
If you want to match the size of another font you see, say in another UILabel, you could do:
CGFloat fontSize = self.label.font.pointSize; // obj-c
let fontSize = CGFloat(label.font.pointSize) // swift
And then assign the size of the font you are setting to be this.
UPDATE
After thorough investigation, the common font size of the UINavigationBar is 34px, which is 17 in your Xcode editor. Remember that you can manually override this view, but that is the default font size.

what is the name of the font name used in iOS as system font

I was trying to set the font of UILabel manually. Previously, I use system font black of size 48.
so label.font = UIFont(name: "", size: CGFLoat(48))
what is the name it should be, to make the text of the label has the same look as system black 48.
Try this:
label.font = UIFont.systemFontOfSize(48)
Note that if this is not the right weight, you can instead (starting in iOS 8.2) call systemFontOfSize:weight:.

Resources