gpt4 book ai didi

ios - 如何在 iOS 的 Storyboard 中使用以编程方式定义的字体?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:16:55 25 4
gpt4 key购买 nike

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

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

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

最佳答案

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

文件:UICustomLabel.h

@interface UICustomLabel : UILabel

@end

文件:UICustomLabel.m

@implementation UICustomLabel
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (id)initWithCoder:(NSCoder *)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/

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