问题
i followed this tutorial and the custom font was shown on my storyboard but when i executed my app (on simulator or device) the font is not reflected. can anyone help. this is what i did:
1- downloaded a .ttf file and copied it to my project
2- added "Fonts Provided By Application" in info.plist and added a row having the name of my custom font.
3- opened storyboard and selected the UILabel i want to have a custom font for, and selected the font as custom then selected my font. the font was shown on the storyboard correctly.
am i missing something?
回答1:
Thank you @Andrey Chernuka and @jcaron. I solved the problem by setting the target membership to my project and then exiting the project (cleaning did not work for some reason) and reopening the project and everything was set. the font name was appearing when i printed print (UIFont.familyNames())
回答2:
Have you added .ttf folder to supporting files only. Then Edit info.Plist like this
Fonts provided by Application take as array
Item 0 as Heiti SC.ttf
now you can set label.font = [UIFont fontWithName:@"Heiti SC" size:15];
Then you also need to add ttf file to copy bundle resources in target build phases.
回答3:
You just follow below steps.
Step 1 - downloaded a .ttf file and copied it to my project Step 2 - added "Fonts Provided By Application" in info.plist and added a row having the name of my custom font.
Step 3 - Display added fonts exist into project or not. copy past into application:didFinishLaunchingWithOptions
NSLog(@"Available fonts: %@", [UIFont familyNames]);
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:
[UIFont fontNamesForFamilyName:
[familyNames objectAtIndex:indFamily]]];
for (indFont=0; indFont<[fontNames count]; ++indFont)
{
NSLog(@" Font name: %@", [fontNames objectAtIndex:indFont]);
}
}
Step 4 - find the name of your font and same name check into story board.
It's definitely works.
来源:https://stackoverflow.com/questions/34154772/custom-font-in-ios-not-reflected-on-device