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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With