views:

391

answers:

2

I would like to put thumbnails in the toolbar like the Photos app. Like the screenshot on the left:

alt text

Is there is a built-in control to do this, or do I have to implement it from scratch?

If the answer is from scratch, any tips?

+3  A: 

This would be a control you'd have to write yourself. I'm not what the best approach would be, but I think I'd go with subclassing a UISlider, drawing the array of images next to each other to create the track, and then using the current image as the handle.

Jasarien
Thanks. How do you think your approach compares to Matt Long's answer?
hgpc
Matt's answer will likely be more performant than basing it on a UISlider subclass. I imagine you'd have a lot more freedom with Matt's approach. However, I do think that using a UISlider as the basis, you'd be able to accomplish this much easier and faster.
Jasarien
+3  A: 

From scratch, is the answer, unfortunately.

You create a custom view and add your array of images as subviews using UIImageView objects incrementing your x position by the the thumbnail width you've determined to use.

Then override the touch events for you custom view. Determine which image view the touch is currently over in -touchesMoved and use Core Animation to animate the current view's scale making it larger than the rest. Add the custom view to your toolbar wrapping your custom view in a UIBarButtonItem using -initWithCustomView.

Remember to enable user interaction on your custom view or you won't receive any touch events. If you need help with the code, update your question with some code specific questions.

Matt Long
Thanks. How do you think your approach compares to Jasarien's answer?
hgpc