关于UIView没有设置backgroundColor引发的惨案
先贴代码 `@implementation TestView
static int count = 0;
(id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// self.backgroundColor = [UIColor redColor];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(test) userInfo:nil repeats:YES];} return self; }
// Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation.
(void)drawRect:(CGRect)rect {
// Drawing code\
[[UIColor greenColor] setFill];
[[NSString stringWithFormat:@"%d",count] drawInRect:self.bounds withFont:[UIFont systemFontOfSize:15]]; }
(void) test {
count++;
[self setNeedsDisplay];
}
我把initWithFrame里设置背景颜色注释掉,发现绘制出来的都是重叠的,而设置设置背景颜色后,却正常了,这是为什么呀?