UI-不常用控件 UIActivityIndicatorView、UIProgressView、UISegmentedControl、UIStepper、UISwitch、UITextView、UIAlertController

1 //UIActivityIndicatorView //小菊花,加载======================================================================================
  2
  3 #import "ActivityIndicatorVC.h"
  4
  5 @interface ActivityIndicatorVC (){
  6     UIActivityIndicatorView *_activity ;
  7 }
  8
  9 @end
 10
 11 @implementation ActivityIndicatorVC
 12
 13 -(void)viewDidLoad{
 14     [super viewDidLoad];
 15
 16     [self createActivityIndicator];
 17
 18 }
 19
 20 -(void)createActivityIndicator{
 21     //创建对象
 22     _activity = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(100, 200, 100, 100)];
 23
 24     _activity.backgroundColor = [UIColor blackColor];
 25
 26     _activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
 27
 28     [self.view addSubview:_activity];
 29
 30     //让状态栏中的activityIndicator显示出来
 31     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
 32
 33     //开始动画
 34     [_activity startAnimating];
 35
 36 }
 37
 38
 39     // 想要停止的话添加
 40     // [_activity stopAnimating];
 41     //[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
 42
 43 @end
 44
 45 // UIProgressView //进度条======================================================================================================
 46 #import "ProgressVC.h"
 47
 48
 49
 50 @implementation ProgressVC{
 51     UIProgressView *_progress ;
 52     NSTimer *_timer;
 53 }
 54
 55
 56 -(void)viewDidLoad{
 57     [super viewDidLoad];
 58
 59     self.btn.hidden = YES;
 60
 61     [self createProgress];
 62
 63     [self createTimer];
 64 }
 65
 66 -(void)createProgress{
 67     _progress = [[UIProgressView alloc]initWithFrame:CGRectMake(50, 100, 200, 50)];
 68     [self.view addSubview:_progress];
 69 //    progress.backgroundColor = [UIColor lightGrayColor];
 70
 71     _progress.tintColor = [UIColor redColor];
 72
 73     _progress.progressTintColor = [UIColor greenColor];
 74     _progress.trackTintColor = [UIColor blueColor];
 75
 76     _progress.progress = 0.01;
 77 }
 78
 79 -(void)createTimer{
 80     _timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(run ) userInfo:nil repeats:YES];
 81 }
 82
 83 -(void)run{
 84     _progress.progress += 0.01;
 85 }
 86
 87 @end
 88
 89
 90   // UISegmentedControl //分段=======================================================================================================
 91
 92 -(void)viewDidLoad{
 93     [super viewDidLoad];
 94
 95     self.btn.hidden = YES;
 96
 97     [self createSegment];
 98 }
 99
100 -(void)createSegment{
101
102     NSArray *items = @[@"00000", @"1111", @"2222"];
103
104     UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:items];
105
106     segment.frame = CGRectMake(50, 100, 300, 40);
107     segment.backgroundColor = [UIColor magentaColor];
108     segment.tintColor = [UIColor yellowColor];
109     segment.selectedSegmentIndex = 0;
110
111     [segment insertSegmentWithTitle:@"4444" atIndex:1 animated:YES];
112     [segment insertSegmentWithImage:[UIImage imageNamed:@"tab_0"] atIndex:1 animated:YES];
113     //让图片显示原始图片
114     UIImage *img = [[UIImage imageNamed:@"tab_0"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
115
116     [segment insertSegmentWithImage:img atIndex:1 animated:YES];
117
118     [self.view addSubview:segment];
119
120     //添加事件
121     [segment addTarget:self action:@selector(segmentSelected:) forControlEvents:UIControlEventValueChanged];
122
123
124 }
125
126 -(void)segmentSelected:(UISegmentedControl *)segment{
127     NSLog(@"%ld", segment.selectedSegmentIndex);
128 }
129
130
131
132 //UIStepper //步进==================================================================================================
133
134 -(void)viewDidLoad{
135     [super viewDidLoad];
136
137     self.btn.hidden = YES;
138
139     [self createStepper];
140 }
141
142 -(void)createStepper{
143     UIStepper *stepper =[[ UIStepper alloc]initWithFrame:CGRectMake(50, 100, 300, 40)];
144     [self.view addSubview:stepper];
145
146     stepper.tintColor = [UIColor redColor];
147     stepper.backgroundColor = [UIColor greenColor];
148
149     stepper.minimumValue = 0;
150     stepper.maximumValue = 100;
151     stepper.stepValue = 5;
152     stepper.wraps = YES;
153     stepper.autorepeat = YES;
154
155     [stepper addTarget:self action:@selector(steperValueChanged:) forControlEvents:UIControlEventValueChanged];
156 }
157
158 -(void)steperValueChanged:(UIStepper *)stepper{
159     NSLog(@"%f", stepper.value);
160
161
162 }
163
164 //UISwitch  //开关======================================================================================================
165
166 -(void)viewDidLoad{
167     [super viewDidLoad];
168
169     self.btn.hidden = YES;
170
171     [self createSwitch];
172 }
173
174 -(void)createSwitch{
175     UISwitch *mySwitch = [[UISwitch alloc]initWithFrame:CGRectMake(50, 100, 200, 40)];
176
177     mySwitch.onTintColor = [UIColor redColor];
178     mySwitch.tintColor = [UIColor greenColor];
179
180     [self.view addSubview:mySwitch];
181
182     [mySwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
183 }
184
185 -(void)switchValueChanged:(UISwitch *)mySwitch{
186     if (mySwitch.isOn) {
187         NSLog(@"on");
188     }  else{
189         NSLog(@"off");
190     }
191 }
192
193
194 //UITextView //文本================================================================================================
195 -(void)viewDidLoad{
196     [super viewDidLoad];
197
198     self.btn.hidden = YES;
199
200     [self createTextView];
201 }
202
203 -(void)createTextView{
204     UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(50, 100, 200, 100)];
205
206     [self.view addSubview:textView   ];
207 }
208
209 //UIAlertController //警报管理===============================================================================
210 - (void)btnClicked {
211
212     UIAlertController *alertCtrl = [UIAlertController alertControllerWithTitle:@"删除" message:@"是否确定要删除该数据" preferredStyle:UIAlertControllerStyleActionSheet];
213     UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil ];
214     UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
215         NSLog(@"具体的删除数据的代码");
216     }];
217
218     [alertCtrl addAction:cancelAction];
219     [alertCtrl addAction:deleteAction];
220
221     [self presentViewController:alertCtrl animated:YES completion:nil];
222
223 }
224
225
226 - (void)btnClicked3 {
227
228     UIAlertController *alertCtrl = [ UIAlertController alertControllerWithTitle:@"警告" message:@"需要输入用户名和密码" preferredStyle:UIAlertControllerStyleAlert];
229     // 添加文本框
230     [alertCtrl addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
231         // 可以对文本框进行设置
232        textField.placeholder = @"用户名";
233     }];
234
235     [alertCtrl addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
236         textField.placeholder = @"密码";
237         textField.secureTextEntry = YES;
238
239         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pwdTextChanged) name:UITextFieldTextDidChangeNotification object:textField];
240     }];
241
242     // 添加一个动作,就是一个按钮
243     UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"登录" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
244         // 用户点击这个按钮的操作
245         NSLog(@"用户名:%@, 密码:%@", alertCtrl.textFields[0].text , alertCtrl.textFields[1].text );
246     }];
247     action2.enabled = NO;
248     [alertCtrl addAction:action2];
249
250     // 弹出提示信息框
251     [self presentViewController:alertCtrl animated:YES completion:nil];
252
253 }
254
255 -(void)pwdTextChanged{
256     // 取得弹出的UIAlertController对象
257     UIAlertController *alertCtrl = (UIAlertController *)  self.presentedViewController;
258     if (alertCtrl) {
259         UIAlertAction *loginAction = alertCtrl.actions.firstObject;
260         loginAction.enabled = YES;
261     }
262
263 }
264
265 - (void)btnClicked2 {
266
267     UIAlertController *alertCtrl = [ UIAlertController alertControllerWithTitle:@"警告" message:@"电量低" preferredStyle:UIAlertControllerStyleAlert];
268
269     UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
270     UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
271         NSLog(@"知道了");
272     }];
273     [alertCtrl addAction:action1];
274     [alertCtrl addAction:action2];
275
276     [self presentViewController:alertCtrl animated:YES completion:nil];
277
278 }
时间: 2024-10-05 18:29:59

UI-不常用控件 UIActivityIndicatorView、UIProgressView、UISegmentedControl、UIStepper、UISwitch、UITextView、UIAlertController的相关文章

[IOS_UI控件] IOS代码实现常用控件UIButton、UISlider、UISwitch、UISegmentedControl

IOS中最常用到的控件UIButton.UISlider.UISwitch.UISegmentedControl通过Xib文件拖动生成非常简单,其实用代码实现也是一样的简单,当然,用代码实现能够掌握到更多的东西. 上图中包涵提到的4种控件,UIButton按钮.UISlider滑块.UISwitch开关.UISegmentedControl分类 首先创建一个名为CodeControls的Empty Application项目 AppDelegate.h和AppDelegate.m文件中和IOS代

UI控件 UIActivityIndicatorView 等待时出现的动态旋转图,以及自定义颜色

#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { //    UIActivityIndicatorView  等待旋转 [super viewDidLoad]; UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 140,

IOS开发基础常用控件简介

在IOS开发中,各类控件完美的解决了开发过程中界面与交互展现的问题,使得IOS产品界面更加灵活实用,IOS常用控件的介绍如下. 1.窗口 UIWindow iPhone的规则是一个窗口,多个视图,窗口是你在app显示出来你看到的最底层,他是固定不变的,基本上可以不怎么理会,但要知道每层是怎样的架构. 2.视图 UIView, 是用户构建界面的基础,所有的控件都是在这个页面上画出来的,你可以把它当成是一个画布,你可以通过UIView增加控件,并利用控件和用户进行交互和传递数据. 窗口和视图是最基本

iOS学习-其他常用控件

1 // 2 // ViewController.m 3 // 其他常用控件 4 // 5 // Created by 大欢 on 16/1/25. 6 // Copyright © 2016年 bjsxt. All rights reserved. 7 // 8 9 #import "ViewController.h" 10 11 @interface ViewController () 12 13 @property (weak, nonatomic) IBOutlet UILab

iOS常用控件尺寸大集合

元素控件 尺寸(pts) Window(含状态栏) 320 x 480 Status Bar的高度 20 Navigation Bar的高度 44 含Prompt的Navigation Bar的高度 74 Navigation Bar的图标 20×20(透明的png) Tool Bar的高度 44 Tool Bar的图标 20×20(透明的png) Tab Bar的高度 49 Tab Bar的图标 30×30(透明的png) 竖直时键盘的高度 216.252(iOS 5+的中文键盘) 水平时键盘

B/S一些小知识及常用控件

一: B/S网页的运行 页面在设计的时候,本身就是一个类.在运行的时间,是一个对象. 其中aspx和aspx.cs是在同一个类下. aspx是主要是负责界面,而aspx.cs主要是负责数据逻辑. 呈现:把页面上所有的控件对象,转化成HTML标签.  内存中的对象--->HTML ** 规范 **: 以后写代码的时候,在Page_Load方法中,99%的代码需要写在 if (!IsPostBack) { } IsPostBack——页面初始加载-false;表单提交加载-true 页面初始加载的情

Windows 8.1 应用再出发 - 几种常用控件

原文:Windows 8.1 应用再出发 - 几种常用控件 本篇为大家简单介绍Windows 商店应用中控件的用法,为方便讲解,我们在文本控件和按钮控件这两类中分别挑选有代表性的控件进行详细说明. 1. 文本控件 (1) TextBlock TextBlock是最常用的文本显示控件,重点关注以下属性: CharacterSpacing  字符之前的统一间距,间距 = 字体大小 / 1000.默认为0,正值增进跟踪和放宽字符间距.负值减少跟踪和收紧字符调间距. IsColorFontEnabled

iOS开发UI篇—UITableview控件基本使

iOS开发UI篇—UITableview控件基本使用 一.一个简单的英雄展示程序 NJHero.h文件代码(字典转模型) #import <Foundation/Foundation.h> @interface NJHero : NSObject /** * 头像 */ @property (nonatomic, copy) NSString *icon; /** * 名称 */ @property (nonatomic, copy) NSString *name; /** * 描述 */ @

Android常用控件:进度条

各种进度条属于 ProgressBar的子类 Sytle: 水平风格:Horizontal小风格:Small大风格:Large反向风格:Inverse小反向风格:Small.Inverse大反向风格:Large.Inverse 设置style:   style="?android:attr/progressBarStyle..." 主要属性:最大值:max当前进度:progress次要进度值:SecondaryProgress --效果类似于看电影那些缓冲 判断进度条是转圈还是水平的方