Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从文本获取CGPath_Iphone_Cgpath_Core Text - Fatal编程技术网

Iphone 从文本获取CGPath

Iphone 从文本获取CGPath,iphone,cgpath,core-text,Iphone,Cgpath,Core Text,Hej fellows 我目前正在尝试将一个字母和/或多个字母转换为CGPathRef,以便手动将它们绘制到自定义UIView中。我尝试了CoreText和framesetter的方法,包括这个小片段,但它似乎不起作用 NSAttributedString *stringToDraw = [[NSAttributedString alloc] initWithString:content

Hej fellows

我目前正在尝试将一个字母和/或多个字母转换为CGPathRef,以便手动将它们绘制到自定义UIView中。我尝试了CoreText和framesetter的方法,包括这个小片段,但它似乎不起作用

NSAttributedString *stringToDraw = [[NSAttributedString alloc] initWithString:content
                                                                       attributes:nil];

    // now for the actual drawing
    CGContextRef context = UIGraphicsGetCurrentContext();

    // flip the coordinate system

    // draw
    CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)stringToDraw);
    CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), NULL, NULL);

    return CTFrameGetPath(frame);

CTFrameGetPath
返回限定
CTFrame
的路径,而不是通过绘制帧生成的路径。我假设您这样做是因为缓存路径以提高以后的绘图性能?(因为
CTFrame
可以轻松地将自身绘制到自定义视图中)

如果您真的想获得
CGPath
,则需要深入到
cglyph
,然后使用
CTFontCreatePathForGlyph
。如果您只是想快速重画文本,我可能会使用
CTFrameDraw
将其绘制到
CGLayer
(而不是
CALayer
)中,以便以后重用

如果您仍然希望glyph使用
CGPath
,请查看。你需要的代码就在那里