Is there something faster than -drawInRect: withFont: lineBreakMode: alignment :?

Shark shows me that this method is a huge success. Like 80% in my table view. All I do is draw two labels per cell (total about 8 per page). While scrolling. i drawInRect: with this.

Are there any better methods? How to draw directly on some layer?

+4
source share
1 answer

You can make a faster drawing using the following code:

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])); 

However, the Mac Roman encoding for the Helvetica font on iPhone lacks characters for many non-English characters, so I think you're stuck with NSString's drawing methods if you don't want to switch to Core Text on iPhone OS 3.2.

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]) 
+5
source

Source: https://habr.com/ru/post/1307806/


All Articles