#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
UIView *firstView;
UIView *secondView;
UIView *thirdView;
}
@property (weak, nonatomic) IBOutlet UISegmentedControl *segment;
- (IBAction)changeValue:(id)sender;
//-------------------------
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
firstView=[[UIView alloc]initWithFrame:CGRectMake(0, 70, 320, 300)];
firstView.backgroundColor=[UIColor redColor];
[self.view addSubview:firstView];
secondView=[[UIView alloc]initWithFrame:CGRectMake(0, 70, 320, 300)];
secondView.backgroundColor=[UIColor greenColor];
thirdView=[[UIView alloc]initWithFrame:CGRectMake(0, 70, 320, 300)];
thirdView.backgroundColor=[UIColor purpleColor];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)changeValue:(id)sender
{
switch (self.segment.selectedSegmentIndex)
{
case 0:
[self.view addSubview:firstView];
[secondView removeFromSuperview];
[thirdView removeFromSuperview];
break;
case 1:
[self.view addSubview:secondView];
[firstView removeFromSuperview];
[thirdView removeFromSuperview];
break;
case 2:
[self.view addSubview:thirdView];
[firstView removeFromSuperview];
[secondView removeFromSuperview];
break;
default:
break;
}
}
@end