Why is this label appearing unstyled?

一曲冷凌霜 提交于 2019-12-13 04:46:07

问题


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

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