如何在iOS中将多行字符串或多行标签创建为CGPath? [英] How to create a multiline string or multiline label as a CGPath in iOS?
问题描述
API是否支持此功能?如果没有,我该怎么办?
Does the API support this? If not, how could I do it?
Core Text中有 CTFontCreatePathForGlyph
,可以翻译单个字符进入一条小路。我可以在循环中使用它来创建字符串作为路径,但是我必须处理间距和字距调整以及所有其他讨厌的事情。我正在寻找一个字符串路径,如果该字符串路径是在UILabel中以相同的字体和大小绘制的,则该字符串路径将看起来相同。
There is CTFontCreatePathForGlyph
in Core Text, which can translate a single character into a path. I could use that in a loop to create my string as a path, but I'd have to deal with spacing and kerning and all the other nasty things. I'm looking for a string path that would looks the same if it was drawn in a UILabel with same font and size.
推荐答案
查看此项目中的UIBezierPath + TextPaths类别: https://github.com/aderussell/string -to-CGPathRef 。
Look at the UIBezierPath+TextPaths category in this project: https://github.com/aderussell/string-to-CGPathRef.
它显示了如何为单行和多行字符串创建路径以及如何在CAShapeLayers中使用它们。
It shows how to create paths for single and multi-line strings and how to use them with CAShapeLayers.
该类别只是一个包装器,内部函数可以在iOS或Mac OS X中使用,您只需要将项目链接到CoreText框架即可。
The category is just a wrapper and the internal functions can be used in iOS or Mac OS X, you just need to link your project to the CoreText framework.
这篇关于如何在iOS中将多行字符串或多行标签创建为CGPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!