有比-drawInRect:withFont:lineBreakMode:alignment:更快的东西吗? [英] Is there something faster than -drawInRect:withFont:lineBreakMode:alignment:?
问题描述
Shark向我展示了此方法带来了巨大的性能损失.就像我的表格视图中的80%.我要做的就是在每个单元格上绘制两个标签(每页总共8个标签).在滚动过程中.我用了drawInRect:.
Shark shows me that this method takes a HUGE performance hit. Like 80% in my table view. All I do is draw two labels per cell (about 8 in total per page). During scrolling. I drawInRect: with that.
有更好的方法吗?像直接绘制到某个图层一样?
Are there some better methods? Like drawing directly to some layer?
推荐答案
您可以使用以下代码来更快地进行绘制:
You can do faster drawing using code like the following:
CGContextSetStrokeColorWithColor(context, strokeColor);
CGContextSetFillColorWithColor(context, strokeColor);
CGContextSelectFont(context, "Helvetica", fontSize, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetTextPosition(context, 0.0f, round(fontSize / 4.0f));
CGContextShowText(context, [text cStringUsingEncoding:NSMacOSRomanStringEncoding], strlen([text cStringUsingEncoding:NSMacOSRomanStringEncoding]));
但是,iPhone上的Helvetica字体的Mac Roman编码缺少许多非英语字符的符号,因此,除非您想在iPhone OS中升级到Core Text,否则我认为您会迷上NSString绘制方法. 3.2.
However, the Mac Roman encoding for the Helvetica font on the iPhone is missing symbols for many non-English characters, so I think you're stuck with the NSString drawing methods unless you want to step up to Core Text in iPhone OS 3.2.
要检查您的字符串是否可以使用Mac Roman字符集表示,请使用类似以下的内容:
To check and see if your string can be represented using the Mac Roman character set, use something like the following:
if ([text canBeConvertedToEncoding:NSMacOSRomanStringEncoding])
这篇关于有比-drawInRect:withFont:lineBreakMode:alignment:更快的东西吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!