I am using CGContextShowText to display text, but when rotating it 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?
Translate your object so that its centre is at (0, 0), then rotate it, then translate it back to where you want.