当前位置:网站首页>[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)
[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)
2022-07-06 08:50:00 【关于小司】
文章目录
UIAlertController
UIAlertController是iOSUI界面的等待提示框控件
注意
- 在iOS 9.0之后 之前的提示对话框 UIAlertView 被弃用
当我们打出 UIAlertView 对象的时候 - 包括一些视频讲解的时候也是把Xcode的编译环境变成了 iOS 9 以下
- 在iOS 9 之后 Xcode 提供了新的UIAlertController 对象来创建对话提示框对象
UIAlertController 的用法
- 创建一个警告提示框对象
- 养成合成存取方法的方法[email protected]
@interface ViewController : UIViewController<UIAlertViewDelegate> {
// 警告框视图对象
UIAlertController* _alertView ;
// 等待提示对象
//当下载或者加载较大的文件时候显示此控件,处于提升等待状态
}
@property(retain, nonatomic) UIAlertController* alertView;
@end
- 同步属性和成员变量
@implementation ViewController// 实现部分
@synthesize alertView = _alertView;
// 等待提示框 此处可不看
@synthesize activityIndicator = _activityIndicator;
- 加一个button使用同一个事件函数
可循环创建 可单独创建 - 循环创建的原因是我把 提示对话框 And 等待提示器 两个按钮在一起创建了
- 按钮创建看另一篇博客 UIBUtton的创建
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(100, 100 + 100 * i, 100, 40);
[btn setTitle:@"警告对话框架" forState:UIControlStateNormal];
// 因为我是循环创建 把标志设置 为了button 事件的引用
btn.tag = 100 + i
- 添加button事件 函数
- 带参数的原因是我们不止一个button
[btn addTarget:self action:@selector(pressBtn :)
forControlEvents:UIControlEventTouchUpInside];
iOS9.0. 以上UIAlertController 创建方法
- 1) iOS 9 之后的 UIAlertController 用法
提示的题目和内容:
_alertView = [UIAlertController alertControllerWithTitle:@"警告"
message:@"手机被我入侵,即将关机,速速打钱"
preferredStyle:UIAlertControllerStyleAlert];
参数1:警告 --是我们提示框的标题
参数2:手机被我入侵,即将关机,速速打钱" ---提示内容
- 2) 添加选项
- 选项一:
UIAlertAction* sure = [UIAlertAction actionWithTitle:@"确定"
style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)
{
NSLog(@"确定");
}];
- 选项二 —cancle
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"取消"
style:UIAlertActionStyleCancel handler:nil];
- 3)添加选项到视图_alertView
- _alertView 是我们创建的提示框视图
[_alertView addAction:sure];
[_alertView addAction:cancel];
- 显示视图
// 显示视图
[self presentViewController:_alertView animated:YES
completion:nil];
效果
UIActivityIndicatorView
- 等待提示对象 --当下载或者加载较大的文件时候显示此控件,处于提升等待状态
// 等待提示对象
//当下载或者加载较大的文件时候显示此控件,处于提升等待状态
UIActivityIndicatorView* _activityIndicator;
UIActivityIndicatorView的创建
- 合成存取方法
@property(retain, nonatomic) UIActivityIndicatorView* activityIndicator;
- 同步属性和成员变量
@synthesize activityIndicator = _activityIndicator;
- 创建button
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(100, 100 + 100 * i, 100, 40);
[btn setTitle:@"提示对话框" forState:UIControlStateNormal];
btn.tag = 100 + i;
[btn addTarget:self action:@selector(pressBtn :) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
- 添加 button 事件
- 等待指示器 宽 高是不可变更的
_activityIndicator = [[UIActivityIndicatorView alloc]
initWithFrame:CGRectMake(100, 300, 80, 80)] ;
- 等待指示器点击变成什么颜色
self.view .backgroundColor = [UIColor whiteColor];
[self.view addSubview:_activityIndicator];
//启动动画屏显示
[_activityIndicator startAnimating];
效果
- 我们点击提示对话框的时候 就会出现图中的圈圈
等待对话框的停用
当我们不需要这个效果的时候,输入这行代码即可不显示动画
//停止等待对话框
[_activityIndicator stopAnimating];
边栏推荐
- LeetCode:剑指 Offer 42. 连续子数组的最大和
- Nacos 的安装与服务的注册
- LeetCode:394. 字符串解码
- Revit secondary development Hof method calls transaction
- 随手记01
- Introduction to the differences between compiler options of GCC dynamic library FPIC and FPIC
- Unsupported operation exception
- [MySQL] multi table query
- visdom可视化实现与检查介绍
- Screenshot in win10 system, win+prtsc save location
猜你喜欢
同一局域网的手机和电脑相互访问,IIS设置
vb.net 随窗口改变,缩放控件大小以及保持相对位置
C language double pointer -- classic question type
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
C语言双指针——经典题型
Using C language to complete a simple calculator (function pointer array and callback function)
Image, CV2 read the conversion and size resize change of numpy array of pictures
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
swagger设置字段required必填
Marathon envs project environment configuration (strengthen learning and imitate reference actions)
随机推荐
使用latex导出IEEE文献格式
sublime text的编写程序时的Tab和空格缩进问题
Deep analysis of C language data storage in memory
sublime text中conda环境中plt.show无法弹出显示图片的问题
Super efficient! The secret of swagger Yapi
LeetCode:39. 组合总和
优秀的软件测试人员,都具备这些能力
Esp8266-rtos IOT development
Current situation and trend of character animation
Compétences en mémoire des graphiques UML
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Mobile phones and computers on the same LAN access each other, IIS settings
CSP first week of question brushing
POI add write excel file
LeetCode:41. 缺失的第一个正数
The network model established by torch is displayed by torch viz
torch建立的网络模型使用torchviz显示
[MySQL] multi table query
生成器参数传入参数
vb. Net changes with the window, scales the size of the control and maintains its relative position