UIControll控制器 复习
#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:@[@"消息",@"联系人",@"电话"]];
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的时候出现的是绿色的小页面
if (seg.selectedSegmentIndex == 0) {
[UIView transitionFromView:self.greenV toView:self.redV duration:1 options:UIViewAnimationOptionTransitionFlipFromBottom completion:^(BOOL finished) {
}];
}
//当控制器的索引值是1的时候出现的是红色的小页面
if (seg.selectedSegmentIndex == 1) {
[UIView transitionFromView:self.redV toView:self.greenV duration:1 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
}];
}
NSLog(@"%ld",seg.selectedSegmentIndex);
}