How to draw NSString at an angle?

Is there a set of string attributes that I can specify that will draw text at an angle when I call:

[label drawAtPoint:textStart withAttributes:attributes]; 
+4
cocoa nsstring macos
source share
2 answers

Here is an example that uses a transform to rotate a drawing context. Essentially, this is exactly the same as setting the color or shadow, just use -concat instead of -set .

 CGFloat rotateDeg = 4.0f; NSAffineTransform *rotate = [[NSAffineTransform alloc] init]; [rotate rotateByDegrees:rotateDeg]; [rotate concat]; // Lock focus if needed and draw strings, images here. [rotate release]; 
+11
source share

NSString itself has no rotation, but you can rotate the context. The line will always be drawn β€œhorizontally” as you move through the coordinate space, but what actual direction that matches depends on the context. Just use NSAffineTransform to unscrew it as needed.

+6
source share

All Articles