1

嗨,有人能给我详细解释一下如何在 iphone 标签上添加自定义字体吗?

我已经在 info.plist 上创建了一个密钥

<key>UIAppFonts</key>
<array>
        <string>custom.ttf</string>
</array>

但不知道下一步是什么。

4

1 回答 1

4

iphone(开发)上的所有自定义字体都应添加到应用程序 info.plist

添加行

<key>UIAppFonts</key>
<array>
        <string>custom.ttf</string>
</array>

然后将 custom.ttf 添加到项目中。

创建 UILabel 的子类

@interface CustomLabel : UILabel {

}

@end

@implementation CustomLabel

- (id)initWithCoder:(NSCoder *)decoder {
    if (self = [super initWithCoder: decoder]) {
        UIColor *textColor = [UIColor colorWithRed:0.20f green:0.20f blue:0.20f alpha:1.0f];
        [self setTextColor:textColor];
        [self setShadowColor:textColor];
        [self setHighlightedTextColor:textColor];
        [self setFont:[UIFont fontWithName:@"custom" size:self.font.pointSize]];
    }
    return self;
}

@end

就是这样,您已准备好使用标签上的自定义字体。

笔记:

对于您在应用程序上添加的每个想要自定义字体的标签,将类标识更改为 CustomLabel(子类 UILabel 的名称)。

于 2012-06-06T20:49:24.487 回答