How to use CGAffineTransformMakeRotation?

user503853 picture user503853 · Apr 20, 2011 · Viewed 42k times · Source

enter image description here

I want to draw text use Quartz 2D. The "menu" direction is wrong. I want "Menu" still readable and have 45 degree with X-axis. Below is my code:

CGContextSelectFont(context, "Arial", 12, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);

CGContextSetRGBFillColor(context, 0, 0, 0, 1); // 6 
CGContextSetRGBStrokeColor(context, 0, 0, 0, 1);

CGContextSetTextMatrix(context, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));   
CGContextSetTextMatrix(context, CGAffineTransformMakeRotation(45)); 
CGContextShowTextAtPoint(context,10, 10, "Menu", 4);

Answer

Krishnabhadra picture Krishnabhadra · Apr 20, 2011

CGAffineTransformMakeRotation expects angle in radians, not in degrees.

#define DEGREES_TO_RADIANS(x) (M_PI * (x) / 180.0)
...

CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(45));