OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在 iOS 的 Storyboard中使用编程定义的字体? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 05:57
标题: ios - 如何在 iOS 的 Storyboard中使用编程定义的字体?

我在 Storyboard中有很多相同风格的UILabel和按钮,而且我还有一个字体列表,如

#define FLOAT_F1  [UIFont systemFontOfSize:18]
#define FLOAT_F2  [UIFont systemFontOfSize:16]

我可以在storyboard中使用这些定义吗?这样,如果标准发生变化,我就不必在storyboard中一一更改。



Best Answer-推荐答案


您可以创建自定义标签,如下所示。

文件:UICustomLabel.h

@interface UICustomLabel : UILabel

@end

文件:UICustomLabel.m

@implementation UICustomLabel
- (id)initWithFrameCGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}
- (id)initWithCoderNSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {

        // [UIFont fontWithName"AmericanTypewriter-Bold" size:self.font.pointSize]
        [self setFont:[UIFont fontWithName“Font_Name" size:self.font.pointSize]];
    }
    return self;
}
@end

然后将类 UICustomLabel 分配给您需要设置的所有 Storyboard 中的每个标签,如下所示。

Set Custom Class To Label

这对你有用。如果您有任何问题,请告诉我。

关于ios - 如何在 iOS 的 Storyboard中使用编程定义的字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29137867/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4