iOS: introduzca dinámicamente UILabel o UITextView en una imagen dentro de la aplicación iPad tocando y arrastrando

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.

¿Alguna idea?

preguntado el 28 de agosto de 12 a las 12:08

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? -

He este 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? -

1 Respuestas

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();
return image;

Respondido 28 ago 12, 12:08

If it works for you would be super if you accepted the answer. - David H

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.