0

I need to annotate on an image.

Probably a simple solution that I am not able to see at the moment.

I need to introduce a UILabel or UITextView onto an image that is currently displaying on the iPad probably by the TouchesBegan/TouchesMoved/TouchesEnded methods (which is something I tried) and then add some text onto the created UILabel or UITextView. Consequently, I need to embed the added text onto that particular image.

Any ideas?

esh
  • 2,842
  • 5
  • 23
  • 39
  • That sounds reasonable. Create a label, add it as a subview to the one holding your image, change its frame (or center) when touches move.... What part of it is giving you trouble? – Phillip Mills Aug 28 '12 at 11:23
  • I have [this](http://stackoverflow.com/questions/6992830/how-to-write-text-on-image-in-objective-c-iphone) method that needs to be implemented in order to embed that text onto the image. And I think `textview.text` will take the string that is inside the UITextView. And then perhaps "destroy" that UITextView. Is this the way to go about this? Or can you think of a better way? – esh Aug 28 '12 at 11:52

1 Answers1

1

So you will create a custom label, move it around, and when the user is done moving it, you will use:

CGSize size = image.size;
UIGraphicsBeginImageContextWithOptions( size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();

// UIImages and CGImageRefs are flipped
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, size.height);
CGContextConcatCTM(context, flipVertical);

CGContextDrawImage(context, rect, [image CGImage]); // draw the image

// CGContextConcatCTM(context, flipVertical); uncomment if the text is flipped - not sure now

[label.text drawAtPoint:label.frame.origin withFont:label.font];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
David H
  • 40,852
  • 12
  • 92
  • 138