Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 0.86 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Using UISlider as UISwitch (Two state object)
  2. UISlider *slider;
  3. [UIView animateWithDuration:0.2 // seconds
  4.                  animations:^{
  5.                    slider.value = (YES) ? 1.0 : 0.0; // modify this line as appropriate
  6.                  }];
  7.        
  8. UISlider* slider = [[UISlider alloc] init];
  9. slider.minimumValue = -3.0f;
  10. slider.maximumValue = 3.0f;
  11.        
  12. -(IBAction)valueChanged:(id)sender {
  13.     // This determines which "step" the slider should be on. Here we're taking
  14.     //   the current position of the slider and dividing by the `self.stepValue`
  15.     //   to determine approximately which step we are on. Then we round to get to
  16.     //   find which step we are closest to.
  17.     float newStep = roundf((questionSlider.value) / self.stepValue);
  18.  
  19.     // Convert "steps" back to the context of the sliders values.
  20.     self.questionSlider.value = newStep * self.stepValue;
  21. }