A mimic of iPhoto's multi-handle slider.
Demo:
The setup is quite easy.
First of all, copy VMMultiHandleSlider.h and VMMultiHandleSlider.m from VMMultiHandleSlider folder in your project.
After that, you can choose to add a Custom View from IB and set its class to VMMultiHandleSlider or you can use initWithFrame: initializer in your code.
To add handle to the slider, use - (void)addHandle:(NSString *)name image:(NSImage *)image initRatio:(float)initRatio valueBlock:(ValueBlock)valueBlock invValueBlock:(ValueBlock)invValueBlock.
namefield is key of that slider, it is used for not only updating value but also KVO bindings. So please make sure it is unique.imageis the handle image, this will be extended to a set of images representing different control states.initRatiois the initial value of this slider. Should be a normalized value between 0 to 1.valueBlockandinvValueBlockas their name indicates, the blocks are used to convert value from normalized ratio to real value.
To get notification if the value of the handles get changed, call - (void)setValueChangedBlock:(ValueChangedBlock)valueChangedBlock and pass in a block which takes a NSDictionary as argument and returns nothing.
The keys in that dictionary are, as you can predict, the names you set while adding handles. And the values are float-point values represented with NSNumber objects that is computed with valueBlock you've set when creating the handle.
VMMultiHandleSlider also supports KVO. To bind the value of a slider to cocoa controls, simply use values.HANDLE_NAME as keyPath, where HANDLE_NAME is the name you've set when you create the object.
For a more detailed example, please refer to the example project I've created in Example folder.
- The handle size is a constant (13x17 points)
- Input validation
- No control state for handles (disable, dragged, etc)
The handle image I've used in the sample project is copied from iPhoto app. :)
