UILabel自定义字体显示*错误*自定义字体 [英] UILabel with custom font displays *wrong* custom font

查看:119
本文介绍了UILabel自定义字体显示*错误*自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个方法在我的iPhone应用程序中嵌入自定义字体。

I'm using this method to embed custom fonts in my iPhone app.

嵌入工作:当我运行以下代码时,会列出字体。 (目前,我以OTF格式嵌入Myriad Pro的所有家庭成员)

The embedding works: When I run the following code, the fonts are listed. (Currently, I'm embedding all family members of Myriad Pro in OTF format)

for( NSString *familyName in [UIFont familyNames] ){
    for( NSString *fntName in [UIFont fontNamesForFamilyName:familyName] ){
        NSLog(@"%@", fntName);
}}



当我尝试将标签的字体设置为MyriadPro或MyriadPro-大胆,这工作正如预期。但是,当我将字体设置为MyriadPro-BoldCond时,标签仍然设置在MyriadPro-Bold中,而不是压缩版本。我的代码:

When I try to set the font of a label to MyriadPro or MyriadPro-Bold, this works just as expected. However, when I set the font to MyriadPro-BoldCond, the label is still set in MyriadPro-Bold instead of the condensed version. (The font names are correct, I checked.) My Code:

[recommendationLabel setFont:[UIFont fontWithName:@"MyriadPro-BoldCond" size:140]];
recommendationLabel.adjustsFontSizeToFitWidth = YES;

什么交易?

编辑:除了下面的Ingve的解决方案,我已经发现 - 至少对于Myriad Pro - 一旦从plist中删除未使用的字体,正确的字体变体就会显示。在这种情况下,我需要删除MyriadPro-SemiBold。 Mindboggling。

In addition to Ingve's solution below, I have found out that – at least for Myriad Pro – the correct font variant gets displayed as soon as I remove unused fonts from the plist. In this case I needed to remove MyriadPro-SemiBold. Mindboggling.

推荐答案

UIFont仅限于每个字体系列两个变体。但是,您可以通过在编辑器中打开其他n-2字体并更改系列名称来解决此问题。

UIFont is limited to two variations per font family. However, you can work around this by opening the additional n-2 fonts in an editor and changing the family name.

在这里回答我自己的问题: http://stackoverflow.com/questions/4715824/uifont-fontwithname-limited -to-loading-2-variations-per-family

Answered my own question about this here: http://stackoverflow.com/questions/4715824/uifont-fontwithname-limited-to-loading-2-variations-per-family

这篇关于UILabel自定义字体显示*错误*自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆