Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios11- UIFont return nil

Tags:

ios

swift

I'm using UIFont to change the default font in my app. the code is working fine on iOS 10 and below but it returns nil on iOS 11 , nothing has changed . I'm using swift 4

this is my code that returning nil :

UIFont(name: "AIranianSans", size: 20)

could you help me ? what is wrong ?

like image 496
j jones Avatar asked Oct 09 '17 05:10

j jones


2 Answers

Try to check the available fonts

for familyName:String in UIFont.familyNames {
    print("Family Name: \(familyName)")
    for fontName:String in UIFont.fontNames(forFamilyName: familyName) {
         print("--Font Name: \(fontName)")
     }
}

May be the font spelling is different.

like image 128
Abhishek Thapliyal Avatar answered Nov 12 '22 19:11

Abhishek Thapliyal


It looks like a custom font which you must have added as a resource in XCode. XCode 9 has a known issue of not adding resources to target when you include resources by drag and drop.

Check the target membership of your .ttf file in the file inspector.enter image description here

like image 8
Puneet Sharma Avatar answered Nov 12 '22 19:11

Puneet Sharma