【发布时间】:2015-11-27 06:11:20
【问题描述】:
我正在开发一个 ipad 应用程序,它有两个目标,但目标的颜色主题会有所不同,例如在 Target1 中,选定的按钮字体颜色为红色,在 Target2 中,选定的按钮字体颜色为绿色。我想知道这在界面生成器本身中是否可行?
提前致谢!!
【问题讨论】:
标签: ios xcode uibutton xcode7 targets
我正在开发一个 ipad 应用程序,它有两个目标,但目标的颜色主题会有所不同,例如在 Target1 中,选定的按钮字体颜色为红色,在 Target2 中,选定的按钮字体颜色为绿色。我想知道这在界面生成器本身中是否可行?
提前致谢!!
【问题讨论】:
标签: ios xcode uibutton xcode7 targets
您可以使用预处理器宏。选择您的目标,转到目标的 Build Settings 部分,找到 Preprocessor Marcro 并为每个目标添加 新宏(例如 Target1 为您的第一个目标和第二个目标的 Target2)。现在你可以使用代码了:
#ifdef Target1
//code for your first target
#elif Target2
//code for your second target
#endif
希望对你有帮助;-)
【讨论】:
你可以使用这个解决方案:
为多个目标创建单个 .h 文件和多个 .m 文件。
//h 文件
@interface AppTheme : NSObject
@property (nonatomic) UIColor *backgroundColor;
@property (nonatomic) UIColor *buttonTextColor;
//and so on.
//you can create classes or protocols for curtain elements of your app
//
@property (nonatomic) ButtonStyle *defaultButtonStyle;
@property (nonatomic) ButtonStyle *destroyButtonStyle;
//and so on where
// Button style has titleColor, titleFont, background and ect.
@end
AppTheme+A.m 你可以像这样定义你的主题:
@implementation
- (instancetype)init {
if (self = [super init]){
self.backgroundColor = [UIColor black];
self.buttonTextColor = [UIColor white];
//and so on
}
return self;
}
@end
对于目标 B,您可以创建其他文件: AppTheme+B.m 你可以像这样定义你的主题:
@implementation
- (instancetype)init {
if (self = [super init]){
self.backgroundColor = [UIColor pinkColor];
self.buttonTextColor = [UIColor yellowColor];
//and so on
}
return self;
}
@end
【讨论】: