Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

UISegmentedControl Tutoria

ipodtouchdudeipodtouchdude Posts: 31Registered Users
edited June 2012 in Tutorial Discussion
Making a simple UISegmentedControl is Easy Peazy.

Create new project. View-based Application. Call it "UISegmentedControl".

20090925-gy3y6u1j6ye7a3sdyi2nqmenp1.png
20090925-kd2k94xr234uhy4et8fsgdc4qs.png

First we build the view. Open the UISegmentedControlViewController.xib found in Resources folder.
Drag UISegmentedControl onto the view.

20090925-jy7ims637bpwgpaeasd61tqwyt.png

Now save and go onto Xcode into your UISegmentedControl.h file.
Type in the following IBOutlet and IBAction.
@interface UISegmentedControlViewController : UIViewController {
	IBOutlet UISegmentedControl *Segment;
}

-(IBAction)changeSeg;

@end

Then place the IBAction in the UISegmentedControl.m file. We will grab the Segment Outlet and place it in the IBAction with the SegmentControl method.
-(IBAction)changeSeg{
	if(Segment.selectedSegmentIndex == 0){
		
	}
	if(Segment.selectedSegmentIndex == 1){
	
	}
}

The "0" is the first tab in the segment control tab and the "1" is the second segment control tab.

Now when we tap "0" the view will change to red or the "1" segment to change the view color to blue we call our action. We might just type this in.
-(IBAction)changeSeg{
	if(Segment.selectedSegmentIndex == 0){
	   self.view.backgroundColor = [UIColor redColor];
	}
	if(Segment.selectedSegmentIndex == 1){
	   self.view.backgroundColor = [UIColor blueColor];
	}
}

Now save. Open the viewcontroller in Interface Builder. Connect your IBOutlet and IBAction onto the UISegmentedControl.

20090925-d61ka15s83nuwm2b1wxkfuub2n.png
Post edited by ipodtouchdude on

Replies

Sign In or Register to comment.