I have this code in the drawRect method
float aValue = .0167f; float fValue = 20; for(int i=1; i<=6; i++) { CGContextSelectFont(context, "Arial", fValue, kCGEncodingMacRoman); CGContextSetCharacterSpacing(context, 0); CGContextSetTextDrawingMode(context, kCGTextFill); NSString *hString = [[NSString alloc] initWithFormat:@"%i",i]; CGContextSetRGBFillColor(context, 1, 1, 1, aValue); CGContextShowTextAtPoint(context, i*25, i*16, [hString UTF8String], [hString length]); aValue += 0.167; fValue += 1; }
I call a method using NSTimer like this
staticTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(refreshUIView) userInfo:nil repeats:YES];
here is refreshUIView
-(void)refreshUIView { [self setNeedsDisplay]; }
The problem is that drawRect does not clear the screen; it just writes what was last written on the screen.
objective-c iphone
coure2011
source share