0
我已經採取了UIView子類,但是它的背景顏色是不會改變讓UIView的子類,但背景色顯示黑色
該類我使用這些方法
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:CGRectMake(50, 80, 200, 200)];
if (self)
{
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect{
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor darkGrayColor]setFill];
CGContextClearRect(context, rect);
CGContextSetLineWidth(context, 2.0);
CGContextBeginPath(context);
CGContextSetStrokeColorWithColor(context, [UIColor orangeColor].CGColor);
CGContextMoveToPoint(context, 1, 1);
CGContextAddLineToPoint(context, 100, 100);
CGContextStrokePath(context); // and draw
}
我調用這個類主視圖控制器
Newclass *obj =[[Newsclass alloc]init];
obj.backgroundColor =[UIColor redColor];
[self.view addsubview :obj];
但背景顏色默認顯示黑色。它不改變
如果我實現背景色代碼初始化以比不改變幀方法或
拉伸RECT方法。
,如果我的代碼是
- (id)initWithCoder:(NSCoder*)aDecoder
比它的方法不叫 請建議我UIView子類的黑色背景顏色如何改變