问题
I have, in starting to programmatically develop a screen, the following:
NSInteger offset = 0;
UIFont *font = [UIFont fontWithName:@"Scurlock" size:80];
UILabel *label = [[UILabel alloc] initWithFrame:(CGRectMake(20, 40 + offset, width, 20))];
[label setFont:font];
[label setText:@"Hello, world!"];
[self.view addSubview:label];
The "Hello, world!" does appear at the intended coordinates, but I have not found a way to change either the font family or font size. Scurlock is a TrueType font included in the app's resources.
How can I say "Display this text in that font at these coordinates" with a UILabel or something comparable like an RTLabel (which I managed to get bold, but not change the font or font size)?
--EDIT--
I have Scurlock.TTF at the top of Supporting Files and the following from the plist:
<key>Fonts provided by application</key>
<array>
<string>Scurlock.TTF</string>
</array>
This results in one 0 in the list printed out for one answer, and the behavior is AFAICT the same whether I specify Scurlock or Scurlock.TTF.
回答1:
• Check your target under "Copy Bundle Resources" to make sure that the font is actually included in the bundle.
• Add the font to your plist if you haven't yet.
• Double check the font name using
for (NSString* family in [UIFont familyNames])
{
NSLog(@"%@", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
NSLog(@" %@", name);
}
See this guide.
回答2:
Take a look at this: Use custom fonts in iPhone App Look at the .plist property that you add, and make sure it's the same name as the one you are trying to load.
来源:https://stackoverflow.com/questions/19161320/why-is-this-label-appearing-unstyled