【发布时间】:2012-10-15 01:37:30
【问题描述】:
我对 UILabel 进行了子类化,并使用 drawrect 方法在屏幕上绘制字符串。这是我的代码:
- (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];
}
它工作正常,但对于我的目的来说它很慢。我需要在不使用[Label setNeedDisplay]; 的情况下绘制字符串,因为需要从主线程调用 setNeedsDisplay。渲染工作需要在后台队列中完成。如果您能给我提供一个小例子,我将不胜感激。任何帮助表示赞赏。
谢谢。
【问题讨论】:
标签: objective-c nsstring subclass drawrect