use*_*363 10 character ios uibezierpath
我是一个iOS新手.如何使我遵循字母表的UIBezierPath说"B".目标是跟踪沿此路径的接触.
提前致谢.
CoreText.framework提供了获取单词路径的方法
见http://www.codeproject.com/Articles/109729/Low-level-text-rendering
代码示例由Ole Begemann创建.对不起,我忘了为名为AnimatedPath的演示下载网址.
CGMutablePathRef letters = CGPathCreateMutable();
CTFontRef font = CTFontCreateWithName(CFSTR("Helvetica-Bold"), 72.0f, NULL);
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
(id)font, kCTFontAttributeName,
nil];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"Hello World!"
attributes:attrs];
CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString);
CFArrayRef runArray = CTLineGetGlyphRuns(line);
// for each RUN
for (CFIndex runIndex = 0; runIndex < CFArrayGetCount(runArray); runIndex++)
{
// Get FONT for this run
CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex);
CTFontRef runFont = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName);
// for each GLYPH in run
for (CFIndex runGlyphIndex = 0; runGlyphIndex < CTRunGetGlyphCount(run); runGlyphIndex++)
{
// get Glyph & Glyph-data
CFRange thisGlyphRange = CFRangeMake(runGlyphIndex, 1);
CGGlyph glyph;
CGPoint position;
CTRunGetGlyphs(run, thisGlyphRange, &glyph);
CTRunGetPositions(run, thisGlyphRange, &position);
// Get PATH of outline
{
CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyph, NULL);
CGAffineTransform t = CGAffineTransformMakeTranslation(position.x, position.y);
CGPathAddPath(letters, &t, letter);
CGPathRelease(letter);
}
}
}
CFRelease(line);
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointZero];
[path appendPath:[UIBezierPath bezierPathWithCGPath:letters]];
CGPathRelease(letters);
CFRelease(font);
Run Code Online (Sandbox Code Playgroud)
用"你需要的词"取代"Hello World!".
对于 Quartz2D 中的绘图,我使用名为 PaintCode ( http://www.paintcodeapp.com/ )的 OSX 应用程序。它基本上是一个矢量绘图应用程序,可以生成您所做的绘图的石英代码。实际上它\xc2\xb4 非常棒。有一个类似的应用程序称为 Opacity 但我还没有尝试过。
\n\n使用此类应用程序,您可以在背景上设置 B 作为引导,并在其上绘制 BezierPath。一旦你\xc2\xb4完成,只需复制生成的代码并将其粘贴到你的项目中。
\n\n希望能帮助到你。
\n| 归档时间: |
|
| 查看次数: |
2550 次 |
| 最近记录: |