开发者

What is the best practice of Drawing/Moving text with Quartz?

I'm new to Iphone development, i want to implement a simple application that some texts can be shown and moved in the view. So i use the following code to implement the main loop:

- (id)initWithCoder:(NSCoder*)coder {

 [NSTimerscheduledTimerWithTimeInterval:(NSTimeInterval)((1.0 / 30.0)) 
    target:selfselector:@selector(mainLoop) userInfo:nilrepeats:TRUE];
 }  
-(void) mainLoop {

// Do some updates
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {开发者_如何学Go

   // Draw many strings like this ...

    UILabel *label = [[UILabel alloc] init];
label.textColor = color;
label.font = font;
label.text = character;
CGRect rect = CGRectMake(posX, posY, width, height);
[label drawTextInRect:rect];
}

But when there are more than 100 text on the screen, the screen refresh will be slow and not smooth. I want to know whether i'm doing the drawing in the right way? I have searched many documents on web but didnt find the answer. I found many ways to draw text on context but I don't know which I should follow. One thing is, I need to use UILabel since I need to set the color. So is there any problem with my code? Should I use a SubView to draw and then addSubView to the main view? or should I use CGLayer? could anyone tell me what is the best practice for this kind of program? Thanks!


I have figured out the answer, I used NSString:drawInRect instead of UILable:drawTextInRect :

-(void)drawRect:(CGRect)rect  
{    
 // Draw many strings like this ...    
 CGContextSetRGBFillColor (context, 1.0, 1.0, 1.0, 0.5);   
 CGRect rect = CGRectMake(x, y, [self getSizeX], [self getSizeY]); 
 [character drawInRect:rect withFont:[UIFont fontWithName:@"Courier" size:fontSize]];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜