2012-05-15 37 views
10

我是iOS新手。如何讓我成爲一個字母表後跟着的UIBezierPath?「B」。目標是跟蹤這條路上的觸摸。iOS UIBezierPath,遵循字體形狀

在此先感謝。

+2

您是否得到了解決方案? –

+0

嗨..你有什麼解決方案嗎? –

回答

0

對於Quartz2D中的圖形,我使用名爲PaintCode的OSX應用程序(http://www.paintcodeapp.com/)。它基本上是一個矢量繪圖應用程序,它可以生成繪圖的石英代碼。其實真的很棒。有一個類似的應用程序稱爲不透明度,但我還沒有嘗試過。

使用這樣的應用程序,您可以在背景上使用B作爲指南,並在其上繪製BezierPath。完成後,只需複製生成的代碼並將其粘貼到項目中即可。

希望它有幫助。

+0

順便說一句,你可以下載一個演示版本。也許這可以滿足你的問題。 – Marcal

7

CoreText.framework提供了獲取字的路徑

看到奧萊Begemann創建http://www.codeproject.com/Articles/109729/Low-level-text-rendering

代碼示例。抱歉,我忘記了名爲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); 

取代的「Hello World!」與 「道你需要」。

+0

請注意,您應該在此處發佈答案的有用觀點,或將您的帖子風險刪除爲[「未答覆」](http://meta.stackexchange.com/q/8259)。如果您願意,您可能仍然包含鏈接,但僅作爲「參考」。答案應該獨立,不需要鏈接。 –

+0

感謝您的提醒 – nova