如何为整个应用程序设置自定义字体? [英] How do I set a custom font for the whole application?
问题描述
有没有办法如何将全局字体[新自定义字体]应用到iphone objective-c中的整个应用程序。
Is there any way to How to Apply global font [new custom font] to whole application in iphone objective-c.
我知道我们可以使用以下方法设置每个标签的字体
I know that we can use below method to set font for each label
[self.titleLabel setFont:[UIFont fontWithName:@"FONOT_NAME" size:FONT_SIZE]];
但我想改变整个申请。
如果有人知道,请帮助我。
But I want to change for whole application. Please help me if anyone know.
推荐答案
显然要完全更改所有UILabel,你需要设置一个类别UILabel并更改默认字体。所以这里有一个解决方案:
Apparently to change ALL UILabels altogether you will need to setup a category on UILabel and change the default font. So here's a solution for you:
创建一个文件CustomFontLabel.h
Create a file CustomFontLabel.h
@interface UILabel(changeFont)
- (void)awakeFromNib;
-(id)initWithFrame:(CGRect)frame;
@end
创建文件CustomFontLabel.m
Create a file CustomFontLabel.m
@implementation UILabel(changeFont)
- (void)awakeFromNib
{
[super awakeFromNib];
[self setFont:[UIFont fontWithName:@"Zapfino" size:12.0]];
}
-(id)initWithFrame:(CGRect)frame
{
id result = [super initWithFrame:frame];
if (result) {
[self setFont:[UIFont fontWithName:@"Zapfino" size:12.0]];
}
return result;
}
@end
现在......在你想要的任何视图控制器中这些自定义字体标签,只包括在顶部:
Now ... in any view controller you want these custom font labels, just include at the top:
#import "CustomFontLabel.h"
这就是全部 - 祝你好运
That's all - good luck
这篇关于如何为整个应用程序设置自定义字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!