简体   繁体   English

添加自定义字体

[英]Add custom font

Is it possible to apply custom (added to the app) font to UILabel text via UIBuilder or it can be done only programmatically ? 是否可以通过UIBuilder将自定义(添加到应用程序)字体应用于UILabel文本,还是只能通过编程方式完成?

I have already added 我已经加了

Fonts provided by application

key in application plist 键入应用程序列表

It can only be done programmaticaly, but it is simple: crate a subclass of UILabel and then overwrite the awakeFromNib method: 它只能通过编程方式完成,但很简单:创建UILabel的子类,然后覆盖awakeFromNib方法:

-(void)awakeFromNib{
   [super awakeFromNib];
   self.font = [UIFont fontWithName:@"MyFancyFont" size:self.font.pointSize];
}

(with this method you keep the font size you set in IB.) (使用这种方法,您可以保持在IB中设置的字体大小。)

In the Identity Inspector in IB you have to set the label to the class you created, in "Custom Class" (where it says "UILabel" now). 在IB的Identity Inspector中,您必须将标签设置为在“自定义类”(现在显示为“ UILabel”)中创建的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM