我正在做的是绘制一个简单的矩形并为绘制区域设置颜色
// Just added
@interface Gradient () {
CGColorRef lightBlueColor;
}
@implementation Gradient
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor lightGrayColor];
NSLog(@"frame is %@",NSStringFromCGRect(self.frame));
NSLog(@"bound is %@",NSStringFromCGRect(self.bounds));
lightBlueColor = [UIColor colorWithRed:105.0f/255.0f green:179.0f/255.0f blue:216.0f/255.0f alpha:1.0].CGColor;
}
return self;
}
-(void) layoutSubviews {
paperRect = CGRectMake(10, 10, self.bounds.size.width/2, self.bounds.size.height/2);
}
-(void)drawRect:(CGRect)rect {
//Draw a retangle
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, lightBlueColor);
CGContextFillRect(context, paperRect);
}
以下是模拟器上显示的内容
但是,当我尝试在设备上安装时,我收到 EXC_BAD_ACCESS
问题 :
为什么它在设备上不起作用。我在某处犯错了吗
编辑:我刚刚尝试修改 lightBlueColor
lightBlueColor = [UIColor blueColor].CGColor;
然后我可以在设备上运行该应用程序。我完全不明白