tags:

views:

489

answers:

1

Hi, I'm trying to figure out a best way to implement the picture-editing capability shown in the native address book app on iPhone.

On the built-in address book, this is how the picture looks like before editing:

qkpic.com/2f7d4

And after clicking edit, notice how "Edit" overlay is added and the image becomes clickable:

qkpic.com/fb2f4

What would be the best way to implement something like this? Should I make the image a button from the beginning and have tapping disabled at first? If so, what steps are required to add an overlay/label to the image (in above example, gray border + the text "Edit" is added)

+1  A: 

The easiest way is to use Interface Builder, create a container view, then add a UIImageView and UILabel as subviews to it. You would position and style the text and the image but set the UILabel to hidden. Make the whole container view respond to touches. It's easy to do since UIView is derived from UIResponder so all you have to do is override touchesEnded. Whenever you want to change the text label, just set the UILabel to hidden=NO.

There's more to it, however. Notice how the image has rounded corners? You'll want to override the UIImageView's drawRect method to implement a custom drawing routine to do that. There's lots of sample code around and it wasn't part of your original question so I'll stop here.

Ramin