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?

2
  • 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? Aug 28, 2012 at 11:23
  • I have this 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, 2012 at 11:52

1 Answer 1

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;
1
  • If it works for you would be super if you accepted the answer.
    – David H
    Aug 28, 2012 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.