Thursday, June 7, 2012

Segment Control

Segment ControlIn this tutorial i will be showing you how to create and use segment controls Features:
  • 1 Label
  • 1 Segment Control
Using segment controls in your apps has great advantages as its basically a multifunction button and are mostly used in a settings page of an app allowing the using to select many options in the view of one button with segments controlling different features

The Code


Play the video to get a step by step walkthrough and all code can be copy and pasted
ViewController.h
    IBOutlet UILabel *label;
    IBOutlet UISegmentedControl *segmentController;
}
-(IBAction)segmentbutton:(id)sender; 


ViewController.m
-(IBAction)segmentbutton:(id)sender {
    if (segmentController.selectedSegmentIndex == 0) {
        label.text = @"Button 1 Was Selected";
    }
    if (segmentController.selectedSegmentIndex == 1) {
        label.text = @"Button 2 Was Selected";
    }
    if (segmentController.selectedSegmentIndex == 2) {
        label.text = @"Button 3 Was Selected";
    }
    if (segmentController.selectedSegmentIndex == 3) {
        label.text = @"Button 4 Was Selected";
    }
    if (segmentController.selectedSegmentIndex == 4) {
        label.text = @"Button 5 Was Selected";
    }    


No comments:

Post a Comment