Skip to content

Instantly share code, notes, and snippets.

@C4Code
Created May 20, 2013 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save C4Code/5614798 to your computer and use it in GitHub Desktop.
Save C4Code/5614798 to your computer and use it in GitHub Desktop.
Connecting a Slider, a Stepper and a Label.
#import "C4WorkSpace.h"
@implementation C4WorkSpace
-(void)setup {
[self createAddObjects];
//calibrate the min/max values
self.myStepper.minimumValue = 0.0f;
self.myStepper.maximumValue = 10.0f;
self.mySlider.minimumValue = 0.0f;
self.mySlider.maximumValue = 10.0f;
}
-(void)sliderWasUpdated:(C4Slider *)slider {
slider.value = [C4Math round:slider.value];
self.myLabel.text = [NSString stringWithFormat:@"%4.2f",slider.value];
self.myStepper.value = slider.value;
[self.myLabel sizeToFit];
}
-(void)stepperWasUpdated:(C4Stepper *)stepper {
self.myLabel.text = [NSString stringWithFormat:@"%4.2f",stepper.value];
self.mySlider.value = stepper.value;
[self.myLabel sizeToFit];
}
-(void)createAddObjects {
//set up the objects
self.myLabel = [C4Label labelWithText:@"values"];
self.myStepper = [C4Stepper stepper];
self.mySlider = [C4Slider slider:CGRectMake(0, 0, 192, 44)];
//position them
CGPoint centerPoint = CGPointMake(self.canvas.center.x,
self.canvas.center.y - 100);
self.myStepper.center = centerPoint;
centerPoint.y += 100;
self.myLabel.center = self.canvas.center;
centerPoint.y += 100;
self.mySlider.center = centerPoint;
//set up action bindings
[self.mySlider runMethod:@"sliderWasUpdated:"
target:self
forEvent:VALUECHANGED];
[self.myStepper runMethod:@"stepperWasUpdated:"
target:self
forEvent:VALUECHANGED];
[self.canvas addObjects:@[self.myStepper,self.myLabel,self.mySlider]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment