How to display text using Quartz on the iPhone?

前端 未结 2 1575
一生所求
一生所求 2021-02-09 05:02

I\'ve been trying to display text using a Quartz context, but no matter what I\'ve tried I simply haven\'t had luck getting the text to display (I\'m able to display all sorts o

2条回答
  •  孤独总比滥情好
    2021-02-09 05:18

    OK, I got it. First off, change your encoding mode to kCGEncodingMacRoman. Secondly, insert this line underneath it:

    CGContextSetTextMatrix(canvas, CGAffineTransformMake(1, 0, 0, -1, 0, 0));
    

    This sets the conversion matrix for text so that it is drawn correctly. If you don't put that line in, your text will be upside down and back to front. No idea why this wasn't the default. Finally, make sure you've set the right fill colour. It's an easy mistake to make if you forget to change from the backdrop colour to the text colour and end up with white-on-white text.

提交回复
热议问题