UIControl

self.view.backgroundColor = [UIColor whiteColor];

//UIControl 控制類

//addTarget:action:forControlEvents

//添加響應事件(滿足什么條件下 讓某人調用某方法)

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

UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"消息",@"電話",@"微信"]];

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

[self.view addSubview:seg];

[seg release];

//選中分段下標

seg.selectedSegmentIndex = 0;

//背景顏色

//? ? seg.backgroundColor = [UIColor blackColor];

//渲染顏色

seg.tintColor = [UIColor lightGrayColor];

//插入新的分段

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

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

[seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];

// red

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

self.redV.backgroundColor = [UIColor redColor];

[self.view addSubview:self.redV];

[_redV release];

//greenV

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

self.greenV.backgroundColor = [UIColor greenColor];

[self.view addSubview:self.greenV];

[_greenV release];

/*****UISlider 滑塊控制器 ******************/

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

sl.backgroundColor = [UIColor yellowColor];

[self.view addSubview:sl];

[sl release];

//顏色設置

//滑過距離的顏色(滑塊左)

sl.minimumTrackTintColor = [UIColor blackColor];

//未滑過距離的顏色(滑塊右)

sl.maximumTrackTintColor = [UIColor redColor];

//滑塊顏色

sl.thumbTintColor = [UIColor greenColor];

//添加響應事件

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

//滑動范圍

//最小值

sl.minimumValue = -100;

//最大值

sl.maximumValue = 1000;

//更新滑塊起始點

sl.value = -100;

/************ UIPageControl 頁碼控制器 ******************/

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

pc.backgroundColor = [UIColor blueColor];

[self.view addSubview:pc];

[pc release];

//頁數

pc.numberOfPages = 5;

//當前頁

pc.currentPage = 2;

//顏色

//頁碼顏色

pc.pageIndicatorTintColor = [UIColor redColor];

//當前頁碼顏色

pc.currentPageIndicatorTintColor = [UIColor yellowColor];

//響應事件

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

/************* UISwicth 開關 ****************/

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

sw.backgroundColor = [UIColor whiteColor];

[self.view addSubview:sw];

[sw release];

//開關屬性

sw.on = YES;

sw.onTintColor = [UIColor redColor];

sw.tintColor = [UIColor blueColor];

sw.thumbTintColor = [UIColor yellowColor];

//響應方法

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

}

#pragma mark - 開關

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

NSLog(@"%d",sw.on);

if (sw.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{

//獲取視圖對象的方式

//1.tag值

//2.屬性

if (seg.selectedSegmentIndex == 0) {

//transition 過度動畫

//參數一:開始視圖

//參數二:結束視圖

//參數三:持續時間

//參數四:動畫選項

//參數五:完成動畫之后調用的block

[UIView transitionFromView:self.greenV toView:self.redV duration:1 options:UIViewAnimationOptionTransitionFlipFromBottom completion:^(BOOL finished) {

}];

}

if (seg.selectedSegmentIndex == 1) {

[UIView transitionFromView:self.redV toView:self.greenV duration:1 options:UIViewAnimationOptionTransitionFlipFromBottom completion:^(BOOL finished) {

}];

}

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

}

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

推薦閱讀更多精彩內容

  • //addTarget:action:forControlEvents: //添加響應事件(滿足什么條件下 讓...
    肉肉要次肉閱讀 230評論 0 1
  • UIControl 控制類 主要學習了分段控制器、滑塊控制器、頁碼控制器、開關、步進控制器 一、分段控制器UISe...
    青花_閱讀 351評論 0 0
  • // UIControl控制類 // addTarget:action:forControlEvents //添加...
    Devili閱讀 304評論 0 0
  • //準備工作 1.刪除Main 2.ARC->MRC(YES->No) 3.刪除文件(ViewConTroller...
    愛吃芒果的淼小豬閱讀 397評論 1 1
  • 第二十天的時候用了重復來設置例行流程,但在這兩天的實踐里出現了很神奇的一幕: 流程中的動作完成之后,接下來它會立馬...
    繁杰杰閱讀 370評論 0 0