2012-05-15 6 views
10

Soy un novato con iOS. ¿Cómo puedo hacer que un UIBezierPath que sigue un alfabeto diga "B"? El objetivo es seguir los toques a lo largo de este camino.iOS UIBezierPath que sigue la forma de una fuente

Gracias de antemano.

+2

¿Obtuviste una solución para esto? –

+0

Hola ... ¿Has encontrado alguna solución? –

Respuesta

0

Para dibujos en Quartz2D utilizo una aplicación OSX llamada PaintCode (http://www.paintcodeapp.com/). Básicamente es una aplicación de dibujo vectorial que generó el código de cuarzo del dibujo que haces. Es bastante impresionante en realidad. Hay una aplicación similar llamada Opacity pero no la he probado.

Con tales aplicaciones, podría tener una B en el fondo como guía y dibujar su BezierPath sobre ella. Una vez que haya terminado, simplemente copie el código generado y péguelo en su proyecto.

Espero que ayude.

+0

BTW, puede descargar una versión demo. Tal vez esto podría ser suficiente para su problema. – Marcal

7

CoreText.framework proporciona métodos para obtener la ruta de la palabra

ver http://www.codeproject.com/Articles/109729/Low-level-text-rendering

ejemplo de código creado por Ole Begemann. Lo siento, olvidé la URL de descarga para la demostración llamada 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); 

reemplazar “Hello World!”, Con "la palabra que necesita".

+0

Tenga en cuenta que debe publicar los puntos útiles de una respuesta aquí, en este sitio, o su publicación corre el riesgo de ser eliminada como ["No es una respuesta"] (http://meta.stackexchange.com/q/8259). Puede incluir el enlace si lo desea, pero solo como una "referencia". La respuesta debería ser independiente sin necesidad del enlace. –

+0

Gracias por su recordatorio – nova

Cuestiones relacionadas