Question

In iOS 7, several of the CGContext text drawing functions were deprecated in favor of Core Text:

Deprecated CGContext Functions

Sometimes Apple suggests specific alternatives to deprecated functions (e.g. "use x instead") but in this case, "x" is simply "Core Text", which isn't all that specific.

So, if I'm just in -drawRect: and I've got my CGContextRef and I'm ready to call CGContextShowGlyphsAtPoint(), what do I do instead? What's the best practice, and what's the simplest Core Text replacement that doesn't require refactoring any drawing code beyond that call (if such a thing exists)?

Bonus points for an answer that concisely answers this for each of the deprecated text functions on that page—I'm most interested in CGContextShowGlyphsAtPoint(), but this could serve as a good reference for others seeking alternatives to any of those functions.

Was it helpful?

Solution

I believe the intention is for CGContextShowGlyphsAtPoint to be replaced by CGContextShowGlyphsAtPositions. You can get the glyph positions with CTRunGetPositionsPtr or (if that returns NULL), CTRunGetPositions.

AFAICT, CGContextShowGlyphsAtPositions also replaces several other former CoreText functions, such as CGContextShowGlyphs, CGContextShowText, and CGContextShowTextAtPoint. Other former CoreText functions like CGContextSelectFont are replaced by multiple new functions (in that case, CGContextSetFont and CGContextSetFontSize). I believe this is all fairly self-explanatory by reading the API.

There may be other deprecated functions I didn't specifically mention, but I figure you get the point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top