2010-05-12 12 views
8
- (void)drawRect:(CGRect)rect { 
    CGContextRef context = UIGraphicsGetCurrentContext(); 


    CGContextSelectFont(context, "Arial", 24, kCGEncodingMacRoman); 


    CGContextShowTextAtPoint(context, 80, 80, "I am Rahul", 7); 





} 

Estoy tratando de dibujar texto como se muestra arriba "Estoy Rahul" pero cuando ejecuto el código,
de texto recibe se muestra, pero se invierte, por lo que está sucediendo, no estoy recibiendo !! ¡¡ayuda!!dibujar texto usando CGContextShowTextAtPoint pero el texto mostrado es invertida,

+0

posible duplicado de [Cómo rotar texto dibujado por cuarzo en el iPhone] (http://stackoverflow.com/ preguntas/1899775/how-to-rotate-text-drawn-by-quartz-on-iphone) – kennytm

Respuesta

26

Puede utilizar este código:

CGContextSetTextMatrix(context, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0)); 
+0

Gracias por la respuesta ... Funcionó para mí. – Rahul

+0

user338322 realmente debería marcar esto como la respuesta, ya que funciona perfectamente. –

+0

Solo para agregar a esto, la razón por la que esto funciona es porque UIKit tiene un sistema de coordenadas diferente para CoreGraphics. – James

14

Esto es más fácil:

- (void)drawRect:(CGRect)rect { 
    NSString* string = @"I am Rahul"; 
    [string drawAtPoint:CGPointMake(80, 80) 
       withFont:[UIFont systemFontOfSize:24]]; 
} 
+0

[string drawAtPoint: withFont:] ha sido privado de Apple. Ahora debe usar [string drawAtPoint: withAttributes:] –

Cuestiones relacionadas