【发布时间】:2013-04-25 19:48:52
【问题描述】:
为什么我的颜色属性总是null?
@interface StreamingMediaControlButton : UIButton
@property (strong, nonatomic) UIColor *color;
@end
@implementation StreamingMediaControlButton
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
_color = [UIColor whiteColor];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
NSLog(@"color: %@", self.color);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, self.color.CGColor);
}
@end
【问题讨论】:
-
你怎么知道它总是
null?另外,现在是color还是iconColor? -
在 initWithFrame 和 Debug 上设置断点。它应该进入 init 方法。如果它不进去,你的属性将永远为空。
-
这个按钮是在 XIB 文件中定义的吗?
-
合成你的颜色对象。
-
自 Xcode 4.4 起您不必合成它
标签: objective-c properties uicolor