1
votes

If we want to reference a font usually we will be using,

Font: For Ex. let font = UIFont(name: "HelveticaNeue",size :14)

In case of using, San Francisco font, I wasn't able to reference the font the same way,

 let font = UIFont(name: "SFUIText-Semibold",size :14)

Instead, I have to reference like this,

 let font = UIFont(name: ".SFUIText-Semibold",size:14)

What is the difference between the both? and how come using a ".(dot)" operator before the font name reference to SF Font.

1
There is no duplicate, I have exactly used the custom font as detailed in above link. But when I try to set the font using 'titleTextAttributes' in UINavigationBar, I wasn't able to load the font self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName : UIFont(name :"SFUIText-Semibold" ,size :14)] The font doesn't gets loaded.Saravanakumar G
Can you post the complete code, how you are setting it to UINavigationBarSohil R. Memon
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName : UIFont(name :"SFUIText-Semibold" ,size :14)]Saravanakumar G

1 Answers

0
votes

I can reference using this below line to my UILabel:

lblTitle.attributedText = NSAttributedString(string: "Event", attributes: [NSFontAttributeName : UIFont(name :".SFUIText-Semibold", size :14)!])

lblTitle.attributedText = NSAttributedString(string: "Event", attributes: [NSFontAttributeName : UIFont(name :"SFUIText-Semibold", size :14)!])

What Have I Done?

I just drag and drop the font named SF-UI-Text-Semibold.otf to my project and make sure you have selected the project for reference.

Then, I added SF-UI-Text-Semibold.otf to info.plist under Fonts provided by application.

Finally, I can used the font anywhere!