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

Mathi Arasan
  • 869
  • 2
  • 10
  • 32
  • 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. – Dovahkiin Oct 23 '15 at 15:00
  • `SF UI Text-Light` is its font family, and font name is `.SFUIText-Light` – DawnSong Dec 02 '16 at 12:46

5 Answers5

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

Community
  • 1
  • 1
d.rozumeenko
  • 126
  • 2
  • 3
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.

newfun
  • 59
  • 1
  • 7
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.

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

Doug Hill
  • 163
  • 1
  • 9
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)!

Markus
  • 1,147
  • 16
  • 26