2012-05-15 3 views
10

私はiOS初心者です。どのようにしてUIBezierPathをアルファベットの後に "B"とするかを指定します。目的は、このパスに沿ってタッチを追跡することです。iOS UIBezierPathはフォントの形に従います

ありがとうございます。

+2

解決方法はありましたか? –

+0

こんにちは..どんな解決策がありましたか? –

答えて

0

Quartz2Dの描画では、PaintCode(http://www.paintcodeapp.com/)というOSXアプリケーションを使用します。これは、基本的にあなたが行う図面のクォーツコードを生成するベクトル描画アプリケーションです。それは実際にはとても素晴らしいです。不透明度と呼ばれる類似のアプリがありますが、試したことはありません。

このようなアプリでは、バックグラウンドでBをガイドとして使用し、BezierPathを描画することができます。いったん完了したら、生成されたコードをコピーしてプロジェクトに貼り付けます。

希望します。

+0

ところで、デモ版をダウンロードできます。たぶんこれはあなたの問題には十分かもしれません。 – Marcal

7

CoreText.frameworkは

はオレBegemannによって作成http://www.codeproject.com/Articles/109729/Low-level-text-rendering

のコード例を参照してください単語のパスを取得するためのメソッドを提供します。申し訳ありませんが、私はAnimatedPathという名前のデモ用のダウンロードURLを忘れていました。

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