xcode OpenSans 字体在 iOS 模拟器中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16636196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:24:11  来源:igfitidea点击:

OpenSans font not working in iOS simulator

objective-cxcodefontsuilabel

提问by swiftcode

I'd like to use the OpenSansfont on a UILabel, but it's not showing up in the iOS simulator. All that appears is the default system font. I have:

我想在 上使用OpenSans字体UILabel,但它没有显示在 iOS 模拟器中。出现的只是默认的系统字体。我有:

1) Added files to project + selected to copy to app folder.

1) 将文件添加到项目 + 选择复制到应用程序文件夹。

2) Added to Info.plist.

2) 添加到 Info.plist。

info.plist

信息.plist

3) Xcode automatically added all fonts to my build phases folder.

3) Xcode 自动将所有字体添加到我的构建阶段文件夹中。

4) Cleaned the project + built it again.

4)清理项目+重新构建它。

And it still doesn't show up! In my code, I have this:

而且还是不显示!在我的代码中,我有这个:

self.itemPrice = [[UILabel alloc] initWithFrame:CGRectMake(230.0, 30.0, 75.0, 30.0)];
        self.itemPrice.adjustsFontSizeToFitWidth = YES;
        self.itemPrice.font = [UIFont fontWithName:@"OpenSans-ExtraBold" size:13.0f];
        self.itemPrice.textAlignment = NSTextAlignmentCenter;
        self.itemPrice.text = [NSString stringWithFormat:@"%@", [Formatters formatPrice:self.item.price]];
        [self.slidingDetailScrollView addSubview:self.itemPrice];

Anyone know what is causing this bizarre bug?

有谁知道是什么导致了这个奇怪的错误?

采纳答案by swiftcode

Fixed it, it was because of this minor error.

修复它,这是因为这个小错误。

self.itemPrice.font = [UIFont fontWithName:@"OpenSans-Extrabold" size:13.0f];

Extrabold, not ExtraBold. I opened up Font Viewer, as recommended, and it showed that under PostScript Name.

Extrabold,不是ExtraBold。我按照建议打开了字体查看器,它在PostScript Name.

I have now used #define's to place a font string name in there and use that throughout my application to avoid user error and literal strings in the middle of my code.

我现在使用#define's 在那里放置一个字体字符串名称,并在整个应用程序中使用它来避免用户错误和代码中间的文字字符串。