当前位置:网站首页>[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];
边栏推荐
- R language ggplot2 visualization: place the title of the visualization image in the upper left corner of the image (customize Title position in top left of ggplot2 graph)
- 软件压力测试常见流程有哪些?专业出具软件测试报告公司分享
- [MySQL] multi table query
- Tdengine biweekly selection of community issues | phase III
- MongoDB 的安装和基本操作
- LeetCode:剑指 Offer 48. 最长不含重复字符的子字符串
- TP-LINK 企业路由器 PPTP 配置
- LeetCode:剑指 Offer 42. 连续子数组的最大和
- Mobile phones and computers on the same LAN access each other, IIS settings
- LeetCode:836. 矩形重叠
猜你喜欢
深度剖析C语言数据在内存中的存储
C语言深度解剖——C语言关键字
Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges
个人电脑好用必备软件(使用过)
查看局域网中电脑设备
[MySQL] multi table query
sublime text的编写程序时的Tab和空格缩进问题
Visual implementation and inspection of visdom
Using C language to complete a simple calculator (function pointer array and callback function)
Marathon envs project environment configuration (strengthen learning and imitate reference actions)
随机推荐
torch建立的网络模型使用torchviz显示
Mobile phones and computers on the same LAN access each other, IIS settings
[embedded] cortex m4f DSP Library
What are the common processes of software stress testing? Professional software test reports issued by companies to share
Visual implementation and inspection of visdom
[MySQL] limit implements paging
After PCD is converted to ply, it cannot be opened in meshlab, prompting error details: ignored EOF
LeetCode:236. 二叉树的最近公共祖先
[embedded] print log using JLINK RTT
使用latex导出IEEE文献格式
marathon-envs项目环境配置(强化学习模仿参考动作)
TP-LINK enterprise router PPTP configuration
JVM quick start
LeetCode:124. 二叉树中的最大路径和
深度剖析C语言指针
egg. JS project deployment online server
Detailed explanation of heap sorting
Pytorch view tensor memory size
【ROS】usb_ Cam camera calibration
广州推进儿童友好城市建设,将探索学校周边200米设安全区域