UIContrll

UIControll控制类

addTarget:action:forControllEvents:

添加响应事件(满足什么条件下 让某人调用方法)

UISegmentedControl

UISegmentedControl *seg=[[UISegmentedControl alloc] initWithtems:@[@"消息" ,@"电话",@"微信"]];

seg.Frame = CGRectMake(100,100,200,40);

[self.view addSubview:seg];

[seg release];

选中分段下标

seg.selectedSegmentIndex = 0;

一般不设置背景颜色  若要设置跟其他设置颜色的方法一样。

渲染颜色

seg.tintColor = [UIColor lightGrayColor];

插入新的分段

[seg insertSegmentWithTitle:@"陌陌" atIndex:2 animated:YES];

创建两个不同颜色的view

self.redv = [[UIView alloc]initWithFrame:CGRectMake(50,200,300,300)];

self.redv.backgrounderColor = [UIColor refColor];

[self.view addSubview:self.redv];

[_redv release];

相同的方法再建另一个颜色

分段控制器的方法调用

-(void)segAction:(UISegmentedControl *)seg{if(seg.selectedSegmentIndex == 0)

[UIView transitionFrameView:self.greenV toView:self.redv duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished){

}];

}

if(seg.selectedSegmentIndex == 1){

[UIView TransitionFromView:self.redv toView:self.greenV duration:1 options:UIViewAnimationOptionTransitionFileFromLeft completion:^(BOOL finished){

}];

UISlider滑块控制器

UISlider *sl = [[UISlider alloc] initWithFrame:CGRectMake(50,50,250,50)];

sl.backgroundColor = [UIColor yellowColor];

[self.view addSubview:sl];

[sl release];

颜色设置:

划过距离的颜色(滑块左)

sl.minimumTrackTintColor = [UIColor blackColor];

未划过的距离颜色(滑块右)

sl.maxmumTrackTintColor =[UIColor redColor];

滑块颜色:

sl.thumbTintColor =[UIColor greenColor];

添加响应事件:

[sl.addTarget:self action:@selection(sliderAction:)forControlEvents:UIControlEventValueChanged];

滑动范围:

最小值:

sl.minimumValue = -100;

最大值:

sl.maximumValue = 1000;

更新滑块的起始点:

sl.value = -100;

滑块控制器的方法调用:

-(void)sliderAction:(UISlider *)sl{

NSLog(@"%f",sl.value);

}

页码控制器:

UIPageControl *pc = [[UIPageControl alloc]initWithFrame:CGRectMake:(50,150,100,50)];

pc.backgroundColor = [UIColor blackColor];

[self.view addSubview:pc];

[pc release];

页数:

pc.numberOfPages = 4;

当前页:

pc.currentPage = 3;

页码颜色:

pc.pageIndicatorTintColor = [UIColor greenColor];

当前页颜色:

pc.currentPageIndicatorTintColor = [UIColor redColor];

响应事件:

[pc.addTarget:self action:@selection(pageAction:)forControlEvents:UIControlEventValueChanged];

页码控制器的方法调用:

-(void)pageAction:(UIPageControl *)page{

NSLog(@"%ld",page.currentPage);

}

开关控制器:

UISwitch *sw = [[UISwitch alloc]initWithFrame:CGRectMake(250,150,100,50)];

sw.backgroundColor = [UIColor whiteColor];

[self.view addSubview:sw];

[sw addTarget:self action:@selector(switchAction:)forControlEvents:UIControlEventValueChanged];

[sw release];

开关属性:

sw.on = YES;

sw.tintColor = [UIColor blackColor];

sw.thumbTintColor = [UIColor redColor];

sw.onTintColor = [UIColor purpleColor];

开关判断:

-(void)switchAction:(UISwitch *)sw{

if(sw.on){

NSLog(@"开启");

}else{

NSLog(@"关闭");

}

}

你可能感兴趣的:(UIContrll)