mysegmen=[[UISegmentedControl alloc]initWithItems:@[@"one",@"two",@"three"]];
mysegmen.frame=CGRectMake(100, 100, 200, 60);
//初始位置
mysegmen.selectedSegmentIndex=1;
mysegmen.tintColor=[UIColor yellowColor];
mysegmen.backgroundColor=[UIColor grayColor];
[self.view addSubview:mysegmen];
[mysegmen addTarget:self action:@selector(changvalue:) forControlEvents:UIControlEventValueChanged];
}
-(IBAction)changvalue:(UISegmentedControl*)sender{
if (sender.selectedSegmentIndex==0) {
self.view.backgroundColor=[UIColor redColor];
}else if (sender.selectedSegmentIndex==1){
self.view.backgroundColor=[UIColor clearColor];
}else{
self.view.backgroundColor=[UIColor blueColor];
}
}