1

I'm quite new to ios development and I'm trying to write text on an image and rotate the text

I wrote the text but I'm trying to rotate it around its center

the idea is to translate the text to put its origin on the center then rotate then retranslate to the original position

Here's my code :

context = UIGraphicsGetCurrentContext();      

txt = @"Hello";
[[UIColor redColor] set];      

CGSize sz = [txt sizeWithFont:font];

rect= CGRectMake(tpoint.x,tpoint.y,sz.width, sz.height);

CGContextTranslateCTM(context, sz.width/2, sz.height/2);
CGContextRotateCTM(context, 0.3);
CGContextTranslateCTM(context, -sz.width/2, -sz.height/2);

[txt drawAtPoint:tpoint withFont:font];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageView.image = newImage;
beryllium
  • 29,669
  • 15
  • 106
  • 125
Ashraf Hussein
  • 589
  • 1
  • 8
  • 19
  • You are on the right path. Just re-read the Quartz 2D docs and figure out the proper math. iOS uses top left as origin and UIImage provided CGImageRefs are upside down. – David H Sep 29 '12 at 14:18
  • http://stackoverflow.com/a/10293425/1059705 may be helpful – Bala Sep 29 '12 at 14:26

0 Answers0