【发布时间】:2012-10-20 05:34:18
【问题描述】:
我正在做的是绘制一个简单的矩形并为绘制区域设置颜色
// 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;
然后我可以在设备上运行应用程序。完全没看懂
【问题讨论】:
标签: ios core-graphics drawrect