【发布时间】:2013-12-12 20:36:35
【问题描述】:
我采用了一个 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 子类黑色背景颜色如何更改
【问题讨论】:
标签: iphone