views:

1053

answers:

3

I'm working on an iphone application (not web app) and I'd like to build a form asking a user to indicate a price range. Instead of using two text fields, I would prefer to use a double slider to set the minimum and the maximum price. I know that it is possible de use a simple slider (sound control for exemple) but i've never seen a double one. Can anyone help ?

+4  A: 

This is not possible without creating a custom control. You'll need to inherit from UIControl or UIView and provide a custom drawRect method. You'll also need to respond to touch and drag events to update the state of the control. I have not done this myself, but I would be prepared for a fairly significant amount of work to get everything to respond and display as expected.

I'm curious as to why you need to have both values specified on a single slider? Why not use two sliders either side-by-side or stacked? It would not require any more input steps than a double slider, and would conform more to standard UI guidelines.

Code Addict
Two knobs on the same slider makes a lot of sense (two values, same axis, changing one changes the bounds of the other). I think it would be worth the trouble and not outside the UI guidelines to make a custom control.
benzado
A: 

I think you can specify multiple thumbs for a single slider if you subclass UISlider, at least I vaguely remember that being possible in MacOSX. But Code Addict is right, you'll probably be better off using the standard controls - a double-thumbed slider seems like it'd be pretty difficult to deal with in the touchscreen environment.

Mark Bessey
Actually I would be VERY interested in seeing this custom implementation. It does make sense for his particular use.
Hector Ramos
A: 

I built such a control and added it to GitHub so feel free to have a look and if you like the control extend it and contribute.

GitHub page: http://github.com/doukasd/DoubleSlider

Blog post (showing a video of how it works): http://dev.doukasd.com/2010/08/double-slider/

Dimitris