问题描述
您好,有人可以给我详细说明如何在iphone标签上添加自定义字体吗?
Hi can someone give me a detail explanation on how to add custom font on iphone labels?
我已经在info.plist上创建了一个密钥
I have already created a key on info.plist
<key>UIAppFonts</key>
<array>
<string>custom.ttf</string>
</array>
但是不知道下一步是什么.
But don't know whats the next step.
推荐答案
iphone(开发)上的所有自定义字体都应添加到应用程序info.plist
All custom font on iphone(development) should be added on app info.plist
添加行
<key>UIAppFonts</key>
<array>
<string>custom.ttf</string>
</array>
然后将custom.ttf添加到项目中.
创建UILabel的子类
Create a subclass of the 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
就这样,您已经准备好使用标签上的自定义字体.
Thats it, you are ready for the custom font on your label.
注意:
对于要在应用程序上添加的每个具有自定义字体的标签,请将类标识更改为CustomLabel(子类UILabel的名称).
For every labels you add on the app that you want to have a custom font, change the class identity to CustomLabel(name of the subclass UILabel).
这篇关于在iPhone上添加自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!