【发布时间】:2014-05-11 13:35:17
【问题描述】:
当我以编程方式将UIView 添加到视图控制器时,我无法将背景颜色更改为任何其他颜色,它始终保持黑色。
- (void)drawRect:(CGRect)rect
{
// Drawing code
self.backgroundColor = [UIColor blueColor];
UIBezierPath *path = [[UIBezierPath alloc] init];
[path moveToPoint:CGPointMake(100, 33)];
[path addLineToPoint:CGPointMake(200, 33)];
path.lineWidth = 5;
[[UIColor redColor] setStroke];
[path stroke];
}
当我将drawrect: 注释掉并将self.backgroundColor = [UIColor blueColor]; 添加到初始化程序时,颜色会发生变化:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor blueColor]
}
return self;
}
为什么会这样?我需要改变什么?其实我希望背景是透明的。
【问题讨论】:
标签: ios objective-c uiview