Tuesday, June 7, 2011

Building a step up/down notched slider for iPhone

If you implement the following delegate method with similar code then you will gain the desired effect as you move the slider with your finger on-screen.

- (IBAction) sliderValueChanged:(UISlider *)sender {
    float value = [sender value];
    if (value < 0.5) {
        value = 0;
    } else if (value > 0.5 && value <1.5) {
        value = 1;
    } else if (value > 1.5 && value <2.5) {
        value = 2;
    } else if (value > 2.5 && value <3.5) {
        value = 3;
    } else if (value > 3.5 && value <4.5) {
        value = 4;
    } else if (value > 4.5 && value <5.5) {
        value = 5;
    } else if (value > 5.5 && value <6.5) {
        value = 6;
    } else if (value > 6.5 && value <7.5) {
        value = 7;
    } else if (value > 7.5 && value <8.5) {
        value = 8;
    } else {
        value = 9;
    }
    self.slider.value = value;
}

0 comments:

Post a Comment