Search code examples
cocoa-touchiosuilabeluislider

Change a UILabels text with a UISliders value


How I could show a UISliders value as a UILabels text?


Solution

  • Add an action to the slider, like this:

    [slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
    

    Where the sliderChanged: method looks something like this:

    - (void)sliderChanged:(UISlider *)slider {
        self.label.text = [NSString stringWithFormat:@"%g", slider.value];
    }