Custom Font not working in iOS 5

末鹿安然 提交于 2019-12-01 11:06:05

问题


I have added Avenir-Next-LT-Pro-Demi-Condensed_5186.ttf font in my resources. Also added the same to Fonts provided by application in my info.plist. In my code I have set the font like this,

titleLabel.font = [UIFont fontWithName:@"Avenir-Next-LT-Pro-Demi-Condensed_5186" size:10];

But this is not working in ios 5 simulators and devices.


回答1:


Try this ,

The font name is not the font file name 

Avenir-Next-LT-Pro-Demi-Condensed_5186.ttf is a file name. simply double click the Avenir-Next-LT-Pro-Demi-Condensed_5186.ttf file it will automatically  open the font reader.Get the font name from top of the font reader navigation bar..

titleLabel.font = [UIFont fontWithName:@"Avenir Next LT Pro" size:10];



回答2:


You have to check what is the font name it is at times different from font file name...

http://codefriends.blogspot.in/2012/04/adding-custom-font-in-xcode.html

Got answer from Add Custom Fonts In Xcode 4.1




回答3:


Follow the steps given below

1.Make sure when you copy the font the "add to target" check box is checked.

2.First select your font show in finder and double click on don make sure your font name must be same as like image

Here font name is"eurofurence light"

3.Add font into .plist file

4.After doing all the things check your font---

 NSLog(@"%@",[UIFont fontNamesForFamilyName:@"Your font"]);

according to font family use Bold and Italic...

Hope this will help to you




回答4:


I just want to add to this answer that not all the time this follows this rule. The best way is register the font in your application and perform a quick check and validate the font name.

Objective-c

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

Swift

 for familyName in UIFont.familyNames() {
        for fontName in UIFont.fontNamesForFamilyName(familyName){
            print(fontName)
        }
    }


来源:https://stackoverflow.com/questions/17037091/custom-font-not-working-in-ios-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!