Today, we will examining sliders. The UISlider will change the value of a a UILabel, or text.
First, let’s start by creating a new view-based application project. For this tutorial, I will name it “Slider.”
In SliderViewController.h
After implementation
Add the following…
IBOutlet UISlider *mainSlider;
IBOutlet UILabel *mainLabel;…Below brace and before @end, add this…
- (IBAction)labelChanged;
Now that our outlets and actions are complete for the project, let’s go into our SliderViewController.m
Add the following…
- (IBAction)labelChanged {
mainLabel.text = mainSlider.value];
}
Now that our code is finished. (Yay!)
Let’s open our SliderViewController.xib to fix up our view.
When you have the view open, go into the Interface builder library and drag both a UISlider and UIlabel onto the screen. Doesn’t matter where, but visible.
Now go into the inspector/connections when you click file’s owner in the view containing the view, first responder, and file’s owner.
From this point, connect mainSlider outlet to the slider. Then mainLabel outlet to the label.
Lastly, then connect labelChanged action to the slider, and a list of options will come up. Click the option “value changed.”
The value changed option means that action being called will have a value changing return.
Now you can build and run. Our final result should be when you scroll the slider, the label value will change.
-Sebastian Shanus
Popularity: 6% [?]

















