gpt4 book ai didi

iphone - 如何在 Interface Builder 和代码之间共享常量?

转载 作者:行者123 更新时间:2023-12-03 19:02:30 25 4
gpt4 key购买 nike

我想知道是否有一种方法可以在 Interface Builder 中使用常量,以避免在不同的地方手动设置相同的颜色(有时这可能是一项非常繁琐的工作......)

目前我在代码中设置颜色并使用#define设置颜色,但显然IB不能使用#define...

最佳答案

我通过对各种控件进行子类化来解决这个问题,以确保整个应用程序具有相同的样式。缺点是您无法在界面生成器中看到样式,只能看到线框。

例如我有一个

@interface MyButton : UIButton 
@end


@implementation MyButton

-(void) initialize{
self.backgroundColor = [UIColor MyButonColor]; // Using a category on UIColor
}

- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
[self initialize];
}
return self;
}

- (id)initWithCoder:(NSCoder *)decoder {
if (self = [super initWithCoder:decoder]) {
[self initialize];
}
return self;
}

关于iphone - 如何在 Interface Builder 和代码之间共享常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1635737/

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