最新写项目用到了drawRect,但是发现backgroundColor 在调用[self setNeedsDisplay]时不能及时生效,于是查了资料,解决办法如下:
超级扎马斯
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
// 下面两句代码的作用就是填充背景色
[[UIColor blueColor] setFill];
UIRectFill(rect);
// 也可以用这两句代码
// CGContextSetFillColorWithColor(context, self.backgroundColor.CGColor);
// CGContextFillRect(context, rect);
}









网友评论