1

I have subclassed an UILabel and i use drawrect method to draw the string on the screen. This is my code:

- (void)drawRect:(CGRect)rect
{
    CGRect   aRect  = self.frame;
    NSMutableArray *Text=[globaltextarray Text];

   [[NSString stringWithCString:[[Text objectAtIndex:labelindexpath.row] cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding]  drawInRect:aRect
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        withFont:[UIFont fontWithName:@"Times New Roman" size:15.0] lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];
   [super drawRect:rect];     
}

It is working fine but it is slow for my purpose. I need to draw the string without using [Label setNeedDisplay]; because setNeedsDisplay needs to be called from the main thread. The rendering work needs to be done in a background queue. I would be grateful if you could provide me with a small example. Any help appreciated.

Thanks.

4

1 回答 1

0

您可以创建一个新的CGContext以在单独的线程上使用CGBitmapContextCreateImage将字符串绘制到 CGImage/UIImage 中,然后将位图(生成的图像)​​绘制到主线程上的视图中。

编辑:例如 检查这篇文章

于 2012-10-15T02:46:30.747 回答