0
我想通过Interface Builder中的NSTextField
为成员变量中的NSTextField
设置背景颜色,以便以后在另一个组件中使用。启动时,NSTextField
的背景颜色设置为透明。无法存储通过InterfaceBuilder设置的NSTextField的背景颜色
@implementation CTTextField
- (id)initWithCoder:(NSCoder*)coder {
self = [super initWithCoder:coder];
if (self) {
[self customize];
}
return self;
}
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self customize];
}
return self;
}
- (void)awakeFromNib {
...
[self customize];
}
- (void)customize {
// Store the user defined background color.
// FIXME: The color is not stored.
m_userDefinedBackgroundColor = self.backgroundColor;
// Disable the background color.
self.backgroundColor = [NSColor colorWithCalibratedWhite:1.0f alpha:0.0f];
...
}
@end
然而,m_userDefinedBackgroundColor
总是黑。
整个CocoaThemes project我正在使用的是GitHub。
我同意冗余呼叫但为什么通过界面生成器中定义的背景颜色不存储在这个不回答我的问题。 – JJD 2012-07-31 07:46:58
因为在第一次调用'-customize'后,您覆盖'self.backgroundColor',并且第二次将'm_userDefinedBackgroundColor'设置为覆盖的值并丢失原始值。我已将代码添加到我的答案中。 – Dmitry 2012-07-31 08:52:13