How to render stretched text in iOS?

前端 未结 3 858
醉梦人生
醉梦人生 2020-12-23 23:51

Given a rectangular area, I want to render some text using a specific font and have the rendered text fill out the rectangle. As in the image below:

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-24 00:37

    You could try CoreText. Get a CTFramesetter, calculate its rect, then calculate the affine transform necessary to compress that rect into the bounds you want and set that as the CTM. Then when you draw the text, it should stretch it appropriately at full quality.

提交回复
热议问题