
Untitled
By: a guest on
May 10th, 2012 | syntax:
None | size: 0.86 KB | hits: 20 | expires: Never
Using UISlider as UISwitch (Two state object)
UISlider *slider;
[UIView animateWithDuration:0.2 // seconds
animations:^{
slider.value = (YES) ? 1.0 : 0.0; // modify this line as appropriate
}];
UISlider* slider = [[UISlider alloc] init];
slider.minimumValue = -3.0f;
slider.maximumValue = 3.0f;
-(IBAction)valueChanged:(id)sender {
// This determines which "step" the slider should be on. Here we're taking
// the current position of the slider and dividing by the `self.stepValue`
// to determine approximately which step we are on. Then we round to get to
// find which step we are closest to.
float newStep = roundf((questionSlider.value) / self.stepValue);
// Convert "steps" back to the context of the sliders values.
self.questionSlider.value = newStep * self.stepValue;
}