gpt4 book ai didi

iphone - 如何为整个应用程序设置自定义字体?

转载 作者:技术小花猫 更新时间:2023-10-29 11:21:15 24 4
gpt4 key购买 nike

有什么方法可以在 iphone objective-c 中将全局字体 [new custom font] 应用于整个应用程序。

我知道我们可以使用下面的方法为每个标签设置字体

[self.titleLabel setFont:[UIFont fontWithName:@"FONOT_NAME" size:FONT_SIZE]];

但我想改变整个应用程序。有知道的请帮帮我。

最佳答案

显然要完全更改所有 UILabel,您需要在 UILabel 上设置一个类别并更改默认字体。所以这里有一个解决方案:

创建文件CustomFontLabel.h

@interface UILabel(changeFont)
- (void)awakeFromNib;
-(id)initWithFrame:(CGRect)frame;
@end

创建文件 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

现在...在您想要这些自定义字体标签的任何 View Controller 中,只需在顶部包含:

#import "CustomFontLabel.h"

就这些-祝你好运

关于iphone - 如何为整个应用程序设置自定义字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7607108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com