views:

349

answers:

2

I am using CGContextShowText to display text, but when rotation using CGAffineTransformation, the rotation axis is located at the left, not at the center of the drawn text, the code I am using is this:

CGContextSaveGState(context);
CGContextSelectFont(context, "Helvetica", 20, kCGEncodingMacRoman);
CGContextSetCharacterSpacing (context, 1);
CGContextSetRGBFillColor (context, 0, 0, 0, 1);
CGAffineTransform xform = CGAffineTransformMake(
            sin(DegreesToRadians(angle)), cos(DegreesToRadians(angle)),
            cos(DegreesToRadians(angle)), -sin(DegreesToRadians(angle)),
            0,  0);

CGContextSetTextDrawingMode (context, kCGTextFill); 


CGPoint degreeDisplayPoint = CGPointMake(100,100);


CGContextShowTextAtPoint(context, degreeDisplayPoint.x, degreeDisplayPoint.y, [angleStringWithDegree cStringUsingEncoding:NSMacOSRomanStringEncoding], [angleStringWithDegree length]); 

CGContextRestoreGState(context);

Any ideas. Thanks for your help.

+3  A: 

Translate your object so that its centre is at (0, 0), then rotate it, then translate it back to where you want.

MrZebra
A: 

Thanks. This is what I was looking. It worked perfectly.

Carlos Hernandez
How about accepting the answer then? :)
MrZebra