#import "RootViewController.h"
@interface RootViewController ()
@property (nonatomic, retain) UIView *redV;
@property (nonatomic, retain) UIView *greenV;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
//? 四種控制器
//1.SegmentedControl
//設置屬性
UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:@[@"消息",@"聯(lián)系人",@"電話"]];
seg.frame = CGRectMake(100, 64, 175, 40);
seg.backgroundColor = [UIColor whiteColor];
[self.view addSubview:seg];
[seg release];
//當前的下角標
seg.selectedSegmentIndex = 2;
seg.tintColor = [UIColor grayColor];
[seg addTarget:self action:@selector(clickseg:) forControlEvents:UIControlEventValueChanged];
//設置了兩個頁面的屬性
//設置紅色小頁面的屬性
self.redV = [[UIView alloc]initWithFrame:CGRectMake(50, 464, 300, 200)];
self.redV.backgroundColor = [UIColor redColor];
[self.view addSubview:self.redV];
[self.redV release];
//設置一個綠色小頁面的屬性
self.greenV = [[UIView alloc]initWithFrame:CGRectMake(50, 464, 300, 200)];
self.greenV.backgroundColor = [UIColor greenColor];
[self.view addSubview:self.greenV];
[self.greenV release];
//2.開關控制器
UISwitch *swi = [[UISwitch alloc]initWithFrame:CGRectMake(100, 120, 50 , 50)];
swi.backgroundColor = [UIColor whiteColor];
[self.view addSubview:swi];
[swi release];
[swi addTarget:self action:@selector(clickswi:) forControlEvents:UIControlEventValueChanged];
//3.大小聲的控制器
UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(50, 200, 100, 40)];
slider.backgroundColor = [UIColor yellowColor];
[self.view addSubview:slider];
[slider release];
//設置最大聲
slider.maximumValue = 1000;
slider.maximumTrackTintColor = [UIColor redColor];
//設置一下最小生
slider.minimumValue = 100;
slider.minimumTrackTintColor = [UIColor orangeColor];
[slider addTarget:self action:@selector(clickslider:) forControlEvents:UIControlEventValueChanged];
//小圓點控制器(最熟悉不過的了)
UIPageControl *pc = [[UIPageControl alloc]initWithFrame:CGRectMake(100, 300, 100, 50)];
pc.backgroundColor = [UIColor blackColor];
[self.view addSubview:pc];
[pc release];
pc.numberOfPages = 4;
pc.currentPage = 0;
pc.pageIndicatorTintColor = [UIColor orangeColor];
pc.currentPageIndicatorTintColor = [UIColor whiteColor];
[pc addTarget:self action:@selector(clickpc:) forControlEvents:UIControlEventValueChanged];
}
//開關控制器的方法
- (void)clickswi: (UISwitch *)swi
{
if (swi.on) {
NSLog(@"開啟");
} else {
NSLog(@"關閉");
}
}
//大小聲控制的方法
- (void)clickslider:(UISlider *)slider
{
NSLog(@"%f",slider.value);
}
//小圓點控制的方法
- (void) clickpc: (UIPageControl *)pc {
NSLog(@"%ld",pc.currentPage);
}
//分開頁面的控制器的方法
- (void)clickseg: (UISegmentedControl *)seg
{
//當控制器的索引值是0的時候出現(xiàn)的是綠色的小頁面
if (seg.selectedSegmentIndex == 0) {
[UIView transitionFromView:self.greenV toView:self.redV duration:1 options:UIViewAnimationOptionTransitionFlipFromBottom completion:^(BOOL finished) {
}];
}
//當控制器的索引值是1的時候出現(xiàn)的是紅色的小頁面
if (seg.selectedSegmentIndex == 1) {
[UIView transitionFromView:self.redV toView:self.greenV duration:1 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
}];
}
NSLog(@"%ld",seg.selectedSegmentIndex);
}