在iphone上添加自定义字体

时间:2012-06-06 20:45:42

标签: iphone

嗨,有人可以给我一个关于如何在iPhone标签上添加自定义字体的详细说明吗?

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

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

但不知道下一步是什么。

1 个答案:

答案 0 :(得分:4)

iphone(开发)上的所有自定义字体都应添加到app 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的名称)。