UIControl

// UIControl控制類

// addTarget:action:forControlEvents

//添加響應(yīng)事件(滿足什么條件讓某人調(diào)用某方法)

/******** 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];

//添加響應(yīng)事件(通過下標值的變化觸發(fā)方法)

[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];

//顏色設(shè)置

//滑過距離的顏色

sl.minimumTrackTintColor= [UIColorblackColor];

//未劃過距離的顏色

sl.maximumTrackTintColor= [UIColorredColor];

//滑塊顏色

sl.thumbTintColor= [UIColoryellowColor];

//添加響應(yīng)事件

[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];

//頁數(shù)

pc.numberOfPages=4;

//當前頁

pc.currentPage=3;

//顏色

//頁碼顏色

pc.pageIndicatorTintColor= [UIColorredColor];

//當前顏色

pc.currentPageIndicatorTintColor= [UIColorgreenColor];

//響應(yīng)事件

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

/***UISwitch開關(guān)***/

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

sw.backgroundColor= [UIColorwhiteColor];

[self.viewaddSubview:sw];

[swrelease];

//開關(guān)屬性

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(@"關(guān)");

}

}

#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過度動畫

//參數(shù)1:開始視圖

//參數(shù)2:結(jié)束視圖

//參數(shù)3:結(jié)束時間

//參數(shù)4:動畫選項

//參數(shù)5:完成動畫之后調(diào)用的block

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

}];

}

if(seg.selectedSegmentIndex==1) {

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

}];

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容