Vladislav
Vladislav

Reputation: 273

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.

Upvotes: 10

Views: 10405

Answers (5)

OMi Shah
OMi Shah

Reputation: 6186

It's "San Francisco (SF) Pro and Compact" font. You can check here https://developer.apple.com/fonts/

Upvotes: 1

meaning-matters
meaning-matters

Reputation: 22946

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.

Upvotes: -1

Lucas Chwe
Lucas Chwe

Reputation: 2768

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)
    }
}

Upvotes: 6

mskw
mskw

Reputation: 10338

font-family: ".SFCompactText-Regular"; font-weight: normal; font-style: normal

Upvotes: 1

Ahmad F
Ahmad F

Reputation: 31645

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.

Upvotes: 3

Related Questions