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 に答える