Get CGPath from Text

前端 未结 1 1047
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-03 10:48

Hej fellows,

I\'m currently trying to convert a letter and/or multiple of them to a CGPathRef for manually drawing them into a custom UIView. I tried the way over Co

相关标签:
1条回答
  • 2021-01-03 11:14

    CTFrameGetPath returns the path the circumscribes the CTFrame, not the path generated by drawing the frame. I assume that you're doing the above because you are caching the paths to improve later drawing performance? (Since CTFrame can easily draw itself into a custom view).

    If you really want to get CGPath, you need to drill all the way down to the CGGlyph and then use CTFontCreatePathForGlyph. If you just want to quickly redraw text, I'd probably draw this into a CGLayer (not CALayer) with CTFrameDraw for later reuse.

    If you still really want the CGPath for the glyphs, take a look at Low-level text rendering. The code you need is in there.

    0 讨论(0)
提交回复
热议问题