UIControl

// UIControl控制类

// addTarget:action:forControlEvents

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

/******** UISegmentedControl分段控制器*********/

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

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

[self.viewaddSubview:seg];

[segrelease];

//选中分段下表

seg.selectedSegmentIndex=0;

//背景颜色

//seg.backgroundColor = [UIColor blackColor];

//渲染颜色

seg.tintColor= [UIColorlightGrayColor];

//插入新的分段

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

//添加响应事件(通过下标值的变化触发方法)

[segaddTarget:selfaction:@selector(segAction:)forControlEvents:UIControlEventValueChanged];

// red

self.redV= [[UIViewalloc]initWithFrame:CGRectMake(50,200,300,300)];

self.redV.backgroundColor= [UIColorgreenColor];

[self.viewaddSubview:self.redV];

[_redVrelease];

//yellow

self.yeV= [[UIViewalloc]initWithFrame:CGRectMake(50,200,300,300)];

self.yeV.backgroundColor= [UIColorgreenColor];

[self.viewaddSubview:self.yeV];

[_yeVrelease];

/*******UISlider滑动控制器******/

UISlider*sl = [[UISlideralloc]initWithFrame:CGRectMake(50,50,200,50)];

sl.backgroundColor= [UIColoryellowColor];

[self.viewaddSubview:sl];

[slrelease];

//颜色设置

//滑过距离的颜色

sl.minimumTrackTintColor= [UIColorblackColor];

//未划过距离的颜色

sl.maximumTrackTintColor= [UIColorredColor];

//滑块颜色

sl.thumbTintColor= [UIColoryellowColor];

//添加响应事件

[sladdTarget:selfaction:@selector(sliderAction:)forControlEvents:UIControlEventValueChanged];

//滑动范围

//最小值

sl.minimumValue= -100;

//最大值

sl.maximumValue=1000;

//更新滑块的起始点

sl.value= -100;

/*UIPageControl页码控制器*/

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

pc.backgroundColor= [UIColorblackColor];

[self.viewaddSubview:pc];

[pcrelease];

//页数

pc.numberOfPages=4;

//当前页

pc.currentPage=3;

//颜色

//页码颜色

pc.pageIndicatorTintColor= [UIColorredColor];

//当前颜色

pc.currentPageIndicatorTintColor= [UIColorgreenColor];

//响应事件

[pcaddTarget:selfaction:@selector(pageAction:)forControlEvents:UIControlEventValueChanged];

/***UISwitch开关***/

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

sw.backgroundColor= [UIColorwhiteColor];

[self.viewaddSubview:sw];

[swrelease];

//开关属性

sw.on=YES;

sw.onTintColor= [UIColorredColor];

sw.tintColor= [UIColorblackColor];

sw.thumbTintColor= [UIColoryellowColor];

[swaddTarget:selfaction:@selector(swAction:)forControlEvents:UIControlEventValueChanged];

}

#pragma mark -

-(void)swAction:(UISwitch*)swh{

if(swh.on) {

NSLog(@"开");

}else{

NSLog(@"关");

}

}

#pragma mark -页码控制器

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

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

}

#pragma mark -滑块控制器

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

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

}

#pragma mark -分段控制器

- (void)segAction:(UISegmentedControl*)seg{

NSLog(@"%ld", seg.selectedSegmentIndex);

//获取视图对象的方式

//1.tag

//2.属性

if(seg.selectedSegmentIndex==0) {

// transition过度动画

//参数1:开始视图

//参数2:结束视图

//参数3:结束时间

//参数4:动画选项

//参数5:完成动画之后调用的block

[UIViewtransitionFromView:self.yeVtoView:self.redVduration:1options:UIViewAnimationOptionTransitionFlipFromLeftcompletion:^(BOOLfinished) {

}];

}

if(seg.selectedSegmentIndex==1) {

[UIViewtransitionFromView:self.redVtoView:self.yeVduration:1options:UIViewAnimationOptionTransitionFlipFromLeftcompletion:^(BOOLfinished) {

}];

}

}

你可能感兴趣的:(UIControl)