Search code examples
iphonecocoa-touchtextcolorscore-graphics

iPhone - Draw white text on black view using CGContext


I can't achieve drawing some white text on a black view using CGContext in a drawRect method.

I do :

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(context, 1.0);
CGContextSelectFont(context, "Helvetica", 20, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);

CGPoint center = self.center;

And then...
Impossible to find the correct method.
I've tried this :

UIFont* font = [UIFont fontWithName:@"Geneva" size:12.0];
[@"Some text" drawAtPoint:center withFont:font];

But it does not work.

I don't find any CGContext method for that. Where is it hidden ?

How may I draw that text in white ?


Solution

  • Works with :

    CGContextShowTextAtPoint (context, center.x, center.y, "Some text", strlen("Some text")); 
    

    But still need some transformations to be displayed not mirrored :-)