在界面构建器中使用自定义字体 [英] Using custom fonts in interface builder
问题描述
我已经搜索了这个网站,但是我发现没有答案的问题。
我已经将自定义字体加载到我的xcode项目中。 A [UIFont fontWithName:@Laconic-Lightsize:19]
的作品。但是界面生成器不喜欢字体。我不能使用IB,它总是显示默认的字体。有没有办法告诉IB,它可以使用字体?
我也有这个问题在Xcode 4中。我的程序,有很多 UILabel
,它们没有 IBOutlets
所以我这样做;
首先,将 UILabel
子类化为 CustomFontLabel
然后,覆盖 awakeFromNib
方法
@implementation CustomFontLabel
- (void)awakeFromNib {
[super awakeFromNib];
self.font = [UIFont fontWithName:@CustomFontNamesize:self.font.pointSize];
}
@end
最后,在Interface Builder> Identity Inspector将类更改为 CustomFontLabel
。
I've searched this site but I just found unanswered questions.
I've loaded a custom font into my xcode project. A [UIFont fontWithName:@"Laconic-Light" size:19]
works. But interface builder doesn't like the font. I can't use it with IB it always shows the default font. Is there a way to tell IB that its ok to use the font?
I have also this problem in Xcode 4. In my program, there are lots of UILabel
which have no IBOutlets
so I do in that way;
First, subclass the UILabel
to CustomFontLabel
Then, override the "awakeFromNib
" method
@implementation CustomFontLabel
- (void)awakeFromNib {
[super awakeFromNib];
self.font = [UIFont fontWithName:@"CustomFontName" size:self.font.pointSize];
}
@end
Finally, in Interface Builder > Identity Inspector change class to CustomFontLabel
.
这篇关于在界面构建器中使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!