10

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.

MGY
  • 7,245
  • 5
  • 41
  • 74
Vladislav
  • 273
  • 3
  • 15
  • 2
    don't provide name to use system font – Lu_ Sep 03 '19 at 06:42
  • I use a lot of custom fonts. I need to do it – Vladislav Sep 03 '19 at 06:46
  • Try to get the fontName and familyName of that font then check that that you are calling the current font name – A.Munzer Sep 03 '19 at 06:54
  • 1
    Are you looking to do this in code, or do you want the current system font which might be outdated tomorrow? Either remove the swift tag from the question, or edit the question to say that you want a way to get the current font in code, without knowing what it is. –  Nov 07 '19 at 22:06

5 Answers5

6

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)
    }
}
Lucas Chwe
  • 2,578
  • 27
  • 17
3

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.

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
1

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

mskw
  • 10,063
  • 9
  • 42
  • 64
  • 2
    It's bad practice to hard-code this. Also, @Vladislav is asking for code, so this answer is not valid. Perhaps you wish to review your critical comments to other answers? – meaning-matters Sep 24 '19 at 08:49
  • 1
    I was just pointing out that he wasn't asking if the code was good or not. He obviously shouldn't hardcode, but the ultimate question is what is the name of the system font. You are doing too much by correcting his code and his intentions. – mskw Sep 25 '19 at 17:56
1

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

OMi Shah
  • 5,768
  • 3
  • 25
  • 34
-1

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.

meaning-matters
  • 21,929
  • 10
  • 82
  • 142
  • He's not asking how. – mskw Sep 23 '19 at 20:18
  • 2
    @mskw Hoping/Assuming you agree that a hard-coded font name is bad practice, what's your better alternative? – meaning-matters Sep 24 '19 at 08:48
  • 1
    I agree, but I feel the actual font name is the answer. Not how his code should look. – mskw Sep 25 '19 at 20:37
  • 1
    The issue with the question is that it’s unclear whether they are looking for a way to get the current system font (iOS 13 at the moment), and automatically get the next system font when it changes (code), or if they are looking for just the current font name, and don’t care if, as soon as the current system font changes, whatever font name they have will be outdated. –  Nov 07 '19 at 22:08