简体   繁体   English

具有自定义字体的UILabel在iOs 5 Simulator中不显示自定义字体

[英]UILabel with custom font doesn't show custom font in iOs 5 Simulator

I am using a custom font with UILabel. 我在UILabel中使用自定义字体。 I copied the font to the Supporting files folder, added it to the info.plist, and set the font in viewDidLoad with an IBOutlet. 我将字体复制到Supporting files文件夹,将其添加到info.plist,然后使用IBOutlet在viewDidLoad中设置字体。 I set the font with -fontWithName:@"7 Segment" size:77.0 , but when I ran the app, it showed Helvetica 17 as the font. 我使用-fontWithName:@"7 Segment" size:77.0设置字体,但是当我运行该应用程序时,它显示Helvetica 17为字体。 I have triple checked the name of the font, and I added an NSLog to show the name of the font the label was set to, and it showed the correct settings. 我对字体名称进行了三重检查,并添加了一个NSLog来显示标签设置为的字体名称,并显示正确的设置。 But, it still showed the wrong font. 但是,它仍然显示错误的字体。 I am using Xcode 4.2 on OS X Lion, with a tab bar storyboard. 我在OS X Lion上使用Xcode 4.2,并带有标签栏情节提要。
Thanks in advance! 提前致谢!
Josh The Geek 乔什·怪胎

EDIT 编辑
I used the code: 我使用了代码:

NSLog(@"%@", [self font]);  
for (NSString *family in [UIFont familyNames]) {  
    for (NSString *font in [UIFont fontNamesForFamilyName:family]) {  
        NSLog(@"%@: %@", family, font);  
        // NSLog(@"%@", font);  
    }  
}

to get a list of the fonts, and it showed 7 Segment: 7_Segment , but when I tried to use the font 7_Segment , it still only showed Helvetica 17. Once again, I'm out of ideas. 要获取字体列表,它显示了7 Segment: 7_Segment ,但是当我尝试使用字体7_Segment ,它仍然仅显示Helvetica17。再次,我没有主意。 Here's a screenshot of it trying to set a font and failing. 这是尝试设置字体失败的屏幕截图。 The background is an image, the orange is the failing font. 背景是图像,橙色是失败的字体。 http://www.evernote.com/shard/s167/sh/a59011cf-7c41-4172-b905-dd38d48591cb/b7a111d2e5096a010eeb5fe03f711df3 http://www.evernote.com/shard/s167/sh/a59011cf-7c41-4172-b905-dd38d48591cb/b7a111d2e5096a010eeb5fe03f711df3

EDIT 2 I tried setting it to AmericanTypewriter, and it worked, so now I know that I have the name wrong. 编辑2我尝试将其设置为AmericanTypewriter,并且它起作用了,所以现在我知道我的名字错误了。 Would someone please help find the name for the font 7 Segment (2D) from http://www.twyman.org.uk/Fonts/ ? 有人可以从http://www.twyman.org.uk/Fonts/帮助找到字体7 Segment(2D)的名称吗? Like I said before, iOs told me both 7 Segment and 7_Segment , but neither work. 就像我之前说的,iOs告诉了我7 Segment7_Segment ,但都没有用。

I had the same problem once. 我曾经有过同样的问题。 The filename of the font is not always the name of the font itself. 字体的文件名并不总是字体本身的名称。 This blog post helped me. 这篇博客文章对我有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM