SF UI Text-Light(New san francisco) font doesn't work
Asked Answered
N

5

7

I am try to change font for a label but it's doesn't work font name:new New san francisco.

Import that font into project and add in info.plist and this is my code

labelname.font = [UIFont fontWithName:@"SF UI Text-Light" size:12];

If I use that's work fine

labelname.font = [UIFont fontWithName:@"HelveticaNeue" size:12];

But New san francisco font doesn't work. I don't know what I miss :(

enter image description here

Niobium answered 24/9, 2015 at 13:18 Comment(2)
check your build phases, make sure these fonts are in the "Copy bundle resources" tab, and try [UIFont fontWithName:@"SFUIText-Light"], eliminate the spaces between them.Autoerotic
SF UI Text-Light is its font family, and font name is .SFUIText-LightRina
S
6

That's happens because you use the wrong System name for the font. Try to use

labelname.font = [UIFont fontWithName:@"SFUIText-Light" size:12];

How to find System font names see here Adding custom fonts to iOS app finding their real names

Sianna answered 9/12, 2015 at 16:30 Comment(0)
S
5

I try to log the system font and find the font name is ".SFUIText-Light" ,so

labelname.font = [UIFont fontWithName:@".SFUIText-Light" size:12];

this is work.

Sultana answered 9/7, 2016 at 1:9 Comment(0)
F
4

Please use https://www.dropbox.com/s/dyw7kl0mtrftjix/San-Francisco-UI-and-COMPACT.zip?dl=0 this link and download the .ttf instead of .otf file. i am sure you got the result, best of luck.

Foilsman answered 13/10, 2015 at 14:16 Comment(0)
B
2

Adding an update: you should be using the system font APIs in UIFont. For example:

UIFont.systemFont(ofSize: 12, weight: .light)

Apple specifically tells developers to no longer rely on a font name or file system representation for the system font.

As an aside, I made up a library for using many of the special features of the SF font in your app. Feel free to check it out: https://github.com/djfitz/SFFontFeatures

Beutner answered 21/11, 2017 at 18:35 Comment(0)
F
2

IMPORTANT, really.

Use this code, it is very, very useful. With it you can know the real name of the font.

let fontFamilyNames = UIFont.familyNames

for familyName in fontFamilyNames {
    print("------------------------------")
    print("Font Family Name = [\(familyName)]")

    let names = UIFont.fontNames(forFamilyName: familyName)
    print("Font Names = [\(names)]")
}

I show you an example.

The Font file (you must add it into your project, as any other file):

Screenshot 1: Font file

The Font file name in "Info.plist" (exactly the same name with the file extension):

Screenshot 2: Info plist

Finally, the output in the log Debug (created by the code)

Screenshot 3: Debug output

So, you can write this font name:

headerLabel.font = UIFont(name:"SFProDisplay-Heavy", size:30)

Use this code. It has saved me time. It is very useful (I think)!

Fat answered 12/8, 2018 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.