1.  UISwitch 开关

 1 - (void)viewDidLoad
 2 {
 3     [super viewDidLoad];
 4     self.view.backgroundColor = [UIColor whiteColor];
 5     self.title = @"开关";
 6     //开关创建
 7     UISwitch * sw = [[UISwitch alloc]initWithFrame:CGRectMake(10, 100, 100, 100)];
 8     //设置开关的位置
 9     sw.center = self.view.center;
10     sw.onTintColor = [UIColor yellowColor];
11     //注册事件  绑定事件
12
13     //UIControlEventValueChanged  触发控件的事件 一旦触发就会让target 调用action方法
14     [sw addTarget:self action:@selector(changeColor:) forControlEvents:UIControlEventValueChanged];
15     //开关的小圆点的颜色
16     sw.thumbTintColor = [UIColor blackColor];
17     //设置开关状态
18     sw.on = YES;
19     [self.view addSubview:sw];
20
21 }
22
23 -(void)changeColor:(UISwitch *)swi
24 {
25     //根据开关的ON属性来设置相应的事件
26     if (swi.on)
27     {
28         self.view.backgroundColor = [UIColor cyanColor];
29         //onTintColor 镂空的颜色
30         swi.onTintColor = [UIColor blueColor];
31         swi.tintColor = [UIColor orangeColor];
32     }
33     else
34     {
35         self.view.backgroundColor = [UIColor whiteColor];
36     }
37 }

2. UISlider 滑块

 1 - (void)viewDidLoad
 2 {
 3     [super viewDidLoad];
 4     self.title = @"滑块";
 5     self.view.backgroundColor = [UIColor whiteColor];
 6     //创建滑块
 7     UISlider * slider = [[UISlider alloc] initWithFrame:CGRectMake(10, 100, 350, 200)];
 8     //最好把值得范围设置在 0 和 1 之间
 9     //最大值
10     slider.maximumValue = 1;
11     //最小值
12     slider.minimumValue = 0;
13     //滑块的当前值
14     slider.value = 0.6;
15     //小于滑块当前值得一边的颜色
16     slider.minimumTrackTintColor = [UIColor redColor];
17     //大于滑块当前值得一边的颜色
18     slider.maximumTrackTintColor = [UIColor cyanColor];
19     //点的颜色
20     slider.thumbTintColor = [UIColor grayColor];
21
22     slider.backgroundColor = [UIColor lightGrayColor];
23
24     //注册事件 绑定事件
25     [slider addTarget:self action:@selector(changeBackgroundColor:) forControlEvents:UIControlEventValueChanged];
26
27     [self.view addSubview:slider];
28 }
29
30 -(void)changeBackgroundColor:(UISlider*)slider
31 {
32     NSLog(@"%.2f",slider.value);
33     self.view.alpha = slider.value;
34 }

3. UIActivityIndicatorView   活动指示器 菊花控件

 1 - (void)viewDidLoad
 2 {
 3     [super viewDidLoad];
 4     self.title = @"菊花";
 5     self.view.backgroundColor = [UIColor whiteColor];
 6
 7     UIActivityIndicatorView * act = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10, 100, 100, 100)];
 8
 9     act.backgroundColor = [UIColor lightGrayColor];
10
11     //设置菊花 控件的样式 三种
12     /*
13
14      typedef NS_ENUM(NSInteger, UIActivityIndicatorViewStyle) {
15      UIActivityIndicatorViewStyleWhiteLarge,
16      UIActivityIndicatorViewStyleWhite,
17      UIActivityIndicatorViewStyleGray,
18      };
19
20      */
21     act.activityIndicatorViewStyle =  UIActivityIndicatorViewStyleGray;
22
23     [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
24     //开始动画
25     [act startAnimating];
26     //结束动画
27     [act stopAnimating];
28     act.center = self.view.center;
29     [self.view addSubview:act];
30
31 }
32
33 //取消 通知栏中的小得 菊花控件 显示  在要退出的视图控制器中实现
34 -(void)viewWillAppear:(BOOL)animated
35 {
36     [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
37 }

4. UIAlertView  弹窗

需要遵守协议   UIAlertViewDelegate

 1 #import "ViewController4.h"
 2
 3 @interface ViewController4 () <UIAlertViewDelegate>
 4
 5 @end
 6
 7 @implementation ViewController4
 8
 9 - (void)viewDidLoad
10 {
11     [super viewDidLoad];
12     self.view.backgroundColor = [UIColor whiteColor];
13     self.title = @"弹窗";
14
15     UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"美食" message:@"我是一专业的吃货" delegate:self cancelButtonTitle:@"不爱吃" otherButtonTitles:@"卡布奇诺",@"肉",@"驴肉火烧",@"干煸芸豆", nil];
16     alert.delegate =self;
17
18     [alert show];
19
20 }
21
22 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
23 {
24     switch (buttonIndex)
25     {
26         case 0://取消按钮
27             NSLog(@"%@",alertView.title);
28             [self.navigationController popToRootViewControllerAnimated:YES];
29             break;
30
31         case 1:
32             NSLog(@"卡布奇诺");
33             break;
34
35         case 2:
36             NSLog(@"肉");
37             break;
38
39         case 3:
40             NSLog(@"驴肉火烧");
41             break;
42
43         case 4:
44             NSLog(@"干煸芸豆");
45             break;
46         default:
47             break;
48     }
49 }

5. UIProgressView  进度条

 1 - (void)viewDidLoad
 2 {
 3     [super viewDidLoad];
 4     self.view.backgroundColor = [UIColor whiteColor];
 5
 6     UIProgressView * progress = [[UIProgressView alloc] initWithFrame:CGRectMake(10, 100, 355, 100)];
 7
 8     //设置样式
 9     progress.progressViewStyle = UIProgressViewStyleBar;
10
11     progress.backgroundColor = [UIColor orangeColor];
12     //进度
13     progress.progress = 0.2;
14     //未完成进度颜色
15     progress.trackTintColor = [UIColor lightGrayColor];
16     //完成进度颜色
17     progress.progressTintColor = [UIColor cyanColor];
18     //每 0.5 s 让 target 调用 selector方法 重复调用
19     // userInfo   time 定时器 的触发信息
20     _time = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(changeProgress:) userInfo:progress repeats:YES];
21     [self.view addSubview:progress];
22 }
23
24 -(void)changeProgress:(NSTimer *)time
25 {
26     UIProgressView * progress = time.userInfo;
27     progress.progress += 0.1;
28 }

6. UIStepper  步进器

 1 - (void)viewDidLoad
 2 {
 3     [super viewDidLoad];
 4     self.view.backgroundColor = [UIColor whiteColor];
 5     self.title = @"步进器";
 6     //大小固定  宽高 无效
 7     UIStepper * stepper = [[UIStepper alloc] initWithFrame:CGRectMake(10, 100, 355, 100)];
 8     //注册事件 绑定事件
 9     [stepper addTarget:self action:@selector(changeLabelValue:) forControlEvents:UIControlEventValueChanged];
10     //步数
11     stepper.stepValue =
12     30;
13     //最大值
14     stepper.maximumValue = 100;
15     //最小值
16     stepper.minimumValue = 0;
17
18     //设置循环
19     stepper.wraps = YES;
20     [self.view addSubview:stepper];
21
22
23     UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(10, 230, 355, 30)];
24     label.text = @"0";
25     label.backgroundColor = [UIColor whiteColor];
26     label.textColor = [UIColor blackColor];
27     label.textAlignment = NSTextAlignmentCenter;
28
29
30     label.tag = 100;
31
32     [self.view addSubview:label];
33
34 }
35
36 -(void)changeLabelValue:(UIStepper *)stepper
37 {
38     UILabel * label = (id)[self.view viewWithTag:100];
39     label.text = [NSString stringWithFormat:@"%.0f",stepper.value];
40 }

7. UISegmentedControl  分段选择器

 1 - (void)viewDidLoad
 2 {
 3     [super viewDidLoad];
 4     self.view.backgroundColor = [UIColor whiteColor];
 5     self.title = @"分段选择器";
 6     // 你以为马里奥是个简单的游戏吗
 7     NSArray * arr = [[NSArray alloc] initWithObjects:@"马里奥",@"路易吉",@"奇诺比奥",@"耀西", nil];
 8
 9     //创建
10     UISegmentedControl * segmented = [[UISegmentedControl alloc] initWithItems:arr];
11     segmented.frame = CGRectMake(10, 100, 355, 50);
12     //默认选择的 下标从0开始  不设置 则默认谁都不选择
13     segmented.selectedSegmentIndex = 2;
14
15 //    segmented.tintColor = [UIColor cyanColor];
16     [self.view addSubview:segmented];
17     //插入
18     [segmented insertSegmentWithTitle:@"库巴" atIndex:2 animated:YES];
19     //删除项
20     [segmented removeSegmentAtIndex:2 animated:YES];
21
22     //注册事件 绑定事件
23     [segmented addTarget:self action:@selector(changeObj:) forControlEvents:UIControlEventValueChanged];
24
25     [segmented removeSegmentAtIndex:2 animated:YES];
26 }
27
28 -(void)changeObj:(UISegmentedControl *)segmented
29 {
30     if (segmented.selectedSegmentIndex == 0)
31     {
32         NSLog(@"马里奥");
33     }
34     else if(segmented.selectedSegmentIndex == 1)
35     {
36         [segmented insertSegmentWithTitle:@"库巴" atIndex:2 animated:YES];
37     }
38 }

8. UITextView 文本显示框

需要遵守 协议  UITextViewDelegate

 1 #import "ViewController8.h"
 2
 3 @interface ViewController8 () <UITextViewDelegate>
 4
 5 @end
 6
 7 @implementation ViewController8
 8
 9 - (void)viewDidLoad
10 {
11     [super viewDidLoad];
12     self.view.backgroundColor = [UIColor cyanColor];
13     self.title = @"文本显示框";
14
15     UITextView * textV = [[UITextView alloc] initWithFrame:CGRectMake(10, 70, 355, 200)];
16
17     //继承于UIScrollView  √√√√√
18     textV.textAlignment = NSTextAlignmentLeft;
19     textV.font = [UIFont systemFontOfSize:15];
20     // 可以设置textView的留白
21     self.automaticallyAdjustsScrollViewInsets = NO;
22
23     textV.textColor = [UIColor blueColor];
24     textV.delegate = self;
25
26     [self.view addSubview:textV];
27
28 }
29
30
31
32 #pragma mark 协议方法
33 -(void)textViewDidBeginEditing:(UITextView *)textView
34 {
35
36 }
37 -(void)textViewDidChange:(UITextView *)textView
38 {
39
40 }
41 -(void)textViewDidChangeSelection:(UITextView *)textView
42 {
43
44 }
45
46 -(void)textViewDidEndEditing:(UITextView *)textView
47 {
48
49 }
50 -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
51 {
52     return YES;
53 }
54 -(BOOL)textViewShouldBeginEditing:(UITextView *)textView
55 {
56     //将要编辑
57     return YES;
58 }
59 -(BOOL)textViewShouldEndEditing:(UITextView *)textView
60 {
61     //
62     return YES;
63 }
64
65
66 - (void)didReceiveMemoryWarning
67 {
68     [super didReceiveMemoryWarning];
69     // Dispose of any resources that can be recreated.
70 }
71
72 @end

9. UIWebView 网页显示控件

 1 - (void)viewDidLoad
 2 {
 3     [super viewDidLoad];
 4
 5     self.view.backgroundColor = [UIColor blueColor];
 6     self.title = @"网页显示控件";
 7
 8     UIWebView * webV = [[UIWebView alloc] initWithFrame:self.view.frame];
 9     NSString * str = @"http://www.baidu.com";
10     //转网址
11     NSURL * url = [NSURL URLWithString:str];
12     //请求
13     NSURLRequest * quest = [NSURLRequest requestWithURL:url];
14     //加载数据
15     [webV loadRequest:quest];
16
17     [self.view addSubview:webV];
18 }

10. UIActionSheet 底部弹窗

需要 遵守协议  UIActionSheetDelegate

 1 - (void)viewDidLoad
 2 {
 3     [super viewDidLoad];
 4     self.view.backgroundColor = [UIColor whiteColor];
 5     // 通过一个按钮的点击 调出 UIActionSheet
 6     UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
 7     btn.frame = CGRectMake(10, 100, 100, 40);
 8     btn.backgroundColor = [UIColor cyanColor];
 9     [btn addTarget:self action:@selector(shared:) forControlEvents:UIControlEventTouchUpInside];
10     btn.tag = 100;
11     [self.view addSubview:btn];
12 }
13
14
15 -(void)shared:(UIButton*)btn
16 {
17     //创建  需要遵守协议  UIActionSheetDelegate
18     UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"分享" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"微信" otherButtonTitles:@"新浪微博",@"百度贴吧",@"豆瓣一刻", nil];
19
20     //设置 sheet 显示
21     [sheet showInView:self.view];
22 }
23
24 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
25 {
26     UIButton * btn = (id)[self.view viewWithTag:100];
27     if (buttonIndex == 0)
28     {
29         NSLog(@"微信");
30         btn.backgroundColor = [UIColor greenColor];
31     }
32     else if(buttonIndex == 1)
33     {
34         NSLog(@"新浪微博");
35         btn.backgroundColor = [UIColor redColor];
36     }
37     else if(buttonIndex == 2)
38     {
39         NSLog(@"百度贴吧");
40         btn.backgroundColor = [UIColor blueColor];
41     }
42     else if(buttonIndex == 3)
43     {
44         NSLog(@"豆瓣一刻");
45         btn.backgroundColor = [UIColor greenColor];
46     }
47     else if(buttonIndex == 4)
48     {
49         NSLog(@"取消");
50         btn.backgroundColor = [UIColor blackColor];
51     }
52 }

11. UIAlertController 弹窗控制器

 1 - (void)viewDidLoad
 2 {
 3     [super viewDidLoad];
 4     self.view.backgroundColor = [UIColor whiteColor];
 5
 6     //// 通过一个按钮的点击 调出 UIAlertController
 7     UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
 8     btn.frame = CGRectMake(10, 100, 100, 40);
 9     btn.backgroundColor = [UIColor cyanColor];
10     [btn addTarget:self action:@selector(alertV:) forControlEvents:UIControlEventTouchUpInside];
11     btn.tag = 100;
12     [self.view addSubview:btn];
13
14 }
15
16 -(void)alertV:(UIButton *)btn
17 {
18     UIAlertController * alertC = [UIAlertController alertControllerWithTitle:@"能力者" message:@"正义联盟" preferredStyle:UIAlertControllerStyleAlert];
19     //preferredStyle UIAlertController
20     //两种
21
22     /*
23
24      typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
25      UIAlertControllerStyleActionSheet = 0,
26      UIAlertControllerStyleAlert
27      } NS_ENUM_AVAILABLE_IOS(8_0);
28
29      */
30     [alertC addAction:[UIAlertAction actionWithTitle:@"超人" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
31         NSLog(@"I am SuperMan");
32     }]];
33
34     [alertC addAction:[UIAlertAction actionWithTitle:@"钢铁侠" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
35         NSLog(@"I am iconMan");
36     }]];
37
38     [alertC addAction:[UIAlertAction actionWithTitle:@"斯凯" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
39         NSLog(@"I am Skey");
40     }]];
41
42     //UIAlertActionStyleDestructive  变红
43     [alertC addAction:[UIAlertAction actionWithTitle:@"郑吒" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
44         NSLog(@"你们这些人,凡人的智慧");
45     }]];
46     // UIAlertController 是一个控制器 , 可以推出 使用 present
47     [self presentViewController:alertC animated:YES completion:nil];
48
49     //按钮 样式
50     //三种
51     /*
52
53      typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
54      UIAlertActionStyleDefault = 0,
55      UIAlertActionStyleCancel,
56      UIAlertActionStyleDestructive
57      }
58
59      */
60 }

转载于:https://www.cnblogs.com/cccccy/p/4817500.html

IOS UI学习 UI 十个小控件 初度学习相关推荐

  1. Android UI设计之十一自定义ViewGroup,打造通用的关闭键盘小控件ImeObser

    2019独角兽企业重金招聘Python工程师标准>>> 转载请注明出处:http://blog.csdn.net/llew2011/article/details/51598682 ...

  2. Panuon.UI.Silver – 开源C# WPF控件库

    Panuon.UI.Silver – 开源C# WPF控件库 Dotnet9 • 2019年12月13日 22:55 • WPF • 阅读 12145 时间如流水,只能流去不流回! 点赞再看,养成习惯 ...

  3. HTML5 Web app开发工具Kendo UI Web中Grid网格控件的使用

    Kendo UI Web中的Grid控件不仅可以显示数据,并对数据提供了丰富的支持,包括分页.排序.分组.选择等,同时还有着大量的配置选项.使用Kendo DataSource组件,可以绑定到本地的J ...

  4. 第31讲 UI组件之 Gallery画廊控件

    第31讲 UI组件之 Gallery画廊控件 1.Gallery的简介 Gallery(画廊)是一个锁定中心条目并且拥有水平滚动列表的视图,一般用来浏览图片,并且可以响应事件显示信息.Gallery只 ...

  5. [Objective-c] IOS图片浏览小控件

    最近空下来整理一下以前写的一些小控件,这是一个图片浏览的控件,使用Objective-c编写.项目是swift的朋友需要自己bridge一下. 一.功能介绍 当用户点击图片进入图片浏览模式,控件会自动 ...

  6. QT小控件-遥控按钮

    QT小控件-遥控按钮 前言 二.使用步骤 1.QT使用自定义控件 2.程序如下: 3.使用说明 总结 前言 一共两种遥控控件,滑动式和点触式. 滑动式按钮 点触式按钮 二.使用步骤 1.QT使用自定义 ...

  7. 【pyqt5学习】——containers相关控件(tab widget、scroll area、stack widget、tool box、MDI area、dock widget)

    目录 1.tab widget 2.scroll area 2.1 使用方法 Step1.拖入QScrollArea ​Step2.改变widget控件布局 ​Step3.设置scrollAreaWi ...

  8. android组件开关按钮,简单聊聊“开关”这个小控件

    开关虽然只是一个小控件,看起来很简单,但其实它的设计也有着大学问.本文和你一起探讨一下~ 一.开关是什么 开关,英文Switch,常被翻译为开关.滑动开关.切换开关,作为界面中可直接操作的元件,提供两 ...

  9. [QT_015]Qt学习之基于条目控件的自定义特性(拖拽+右键菜单+样式)

    本文转自:<Qt编程指南>        作者:奇先生 Qt编程指南,Qt新手教程,Qt Programming Guide 本节介绍基于条目控件的定制特性,首先介绍条目的拖拽,列表控件. ...

  10. 如何在Android实现桌面清理内存简单Widget小控件

    如何在Android实现桌面清理内存简单Widget小控件 我们经常会看到类似于360.金山手机卫士一类的软件会带一个widget小控件,显示在桌面上,上面会显示现有内存大小,然后会带一个按键功能来一 ...

最新文章

  1. linux 搭建dns
  2. 学习CSS了解单位em和px的区别
  3. 【软件使用】Windows下的Objective-C集成开发环境搭建(IDE)
  4. git stash 强制恢复_git操作与分支管理规范
  5. 对广晟有色的数据分析
  6. tomcat 启动时内存溢出
  7. Tab栏切换布局分析
  8. python中有数组吗_python有数组吗
  9. UVA10921 Find the Telephone【编码】
  10. python中对象的概念是什么_python面向对象编程的基本概念
  11. 好久不上来,发现这个世界变得真是快啊,都.NET 2.0 AJAX了~~
  12. 《第一本docker书》第4章 使用docker镜像和仓库 读书笔记
  13. 机器学习笔记(二):矩阵、环境搭建、NumPy | 凌云时刻
  14. 新版《中国药典》提升中药标准
  15. 我的微信小程序登陆界面
  16. PCL包围盒(详细介绍)
  17. linux下安装了lxml但依然报错rom lxml import etreeModuleNotFoundError: No module named ‘lxml‘
  18. RGBD相机的标定和图像配准
  19. 申请 NVIDIA vGPU 90天试用 LICENSE
  20. Codeforces Round #717 Div.2

热门文章

  1. UVA - 1589 Xiangqi (象棋)
  2. Adjustment Office
  3. 你想要的宏基因组-微生物组知识全在这(2020.10)
  4. nginx 499状态码
  5. 今日芯声 | 每天徒步7公里找信号?印度不愧是开挂民族
  6. Java基础-运算符
  7. 动图GIF图片怎么制作?教你一键搞定
  8. 怎么写加密邮件,企业邮箱支持吗?【企业邮箱注册】
  9. 你和财务自由之间,只差洋哥的这些建议!!!
  10. plot函数--R语言