Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
341 views
in Technique[技术] by (71.8m points)

objective c - Adding custom fonts to iOS app finding their real names

I have two fonts to add in my app for using.

Here is the font images. Currently the files are named as

name.font       = [UIFont fontWithName:@"Helvetica Neue LT Pro-Medium" size:10];
headline.font   = [UIFont fontWithName:@"Helvetica Neue LT Pro-Light" size:8];

putting same name in the Font Avaliable option in plist file.

I have also tried adding file names like

HelveticaNeueLTPro-Lt
HelveticaNeueLTPro-Md

but nothing seems to work. How can i get the exact name of the fonts.

enter image description here

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use +[UIFont familyNames] to list all of the font family names known to the system. For each family name, you can then use +[UIFont fontNamesForFamilyName:] to list all of the font names known to the system. Try printing those out to see what name the system expects. Example code:

static void dumpAllFonts() {
    for (NSString *familyName in [UIFont familyNames]) {
        for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
            NSLog(@"%@", fontName);
        }
    }
}

Put that in your app, call it, and see what you get. If you see a name in the output that looks appropriate for your font, use it. Otherwise, perhaps you haven't properly added the font to your app.

In swift 4.2+ use code given below:

func dumpAllFonts() {
        for familyName in UIFont.familyNames {
            for fontName in UIFont.fontNames(forFamilyName: familyName) {
                print("(fontName)")
            }
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...