UIAlertController、UIAlertAction 警告框
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying> //创建操作
+ (instancetype)actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void (^ __nullable)(UIAlertAction *action))handler; NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertController : UIViewController //初始化
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle; //添加操作
- (void)addAction:(UIAlertAction *)action; 示例1:最简单的提醒视图 //创建操作
UIAlertAction *okAlert = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
//具体操作内容
}];
//初始化
UIAlertController *alert = [UIAlertControlleralertControllerWithTitle:@"顶部标题栏"message:@"中间信息"preferredStyle:UIAlertControllerStyleAlert];
//添加操作
[alert addAction:okAlert];
//以model形式,显示警告视图
[self presentViewController:alert animated:YES completion:nil]; // 等同于
NSString *title = @"顶部标题栏";
NSString *message = @"中间信息";
NSString *okAlertButton = @"OK";
UIAlertAction *okAlert = [UIAlertAction
actionWithTitle:okAlertButton style:UIAlertActionStyleDefaulthandler:^(UIAlertAction * _Nonnull action) { }]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; 示例2:多个按键的提醒视图 //取消按键——下次下次 UIAlertActionStyleCancel (粗体)
[alert addAction:[UIAlertAction actionWithTitle:@"下次下次" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击取消按钮");
}]]; //红色按键——残忍拒绝 UIAlertActionStyleDestructive
[alert addAction:[UIAlertAction actionWithTitle:@"残忍拒绝" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"红色按钮");
}]]; // 两个会是这样 // 3个就挨个往下排
//普通按键——立马好评 UIAlertActionStyleDefault [alert addAction:[UIAlertAction actionWithTitle:@"立马好评" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"普通按钮");
}]]; 示例3:带对话框TextField - (void)addTextFieldWithConfigurationHandler:(void (^ __nullable)(UITextField *textField))configurationHandler; //添加TextField 条栏 addTextFieldWithConfigurationHandler
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
NSLog(@"TextField");
//中间的提示输入
textField.placeholder = @"用来提示你做什么事的";
}]; 示例4:提醒图标,在最底部呈现 Sheet // UIAlertControllerStyleAlert改成UIAlertControllerStyleActionSheet (最后面的)
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertControllerStyleActionsheet好像不能和TextField在一起,会报错。是这样吗? 疑问:排列没有次序?
用英文@“ok” 之类的,就会排列和我写的顺序一样。
instancetype)actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void (^ __nullable)(UIAlertAction *action))handler;
NSString *message = @"中间信息";
NSLog(@"红色按钮");
NSLog(@"普通按钮");
}];
UIAlertController、UIAlertAction 警告框的更多相关文章
- IOS开发中UIAlertController(警告框)的使用
步骤一.初始化: UIAlertController * inputname = [UIAlertController alertControllerWithTitle:@"未输入账户&qu ...
- iOS 学习笔记 九 (2015.04.02)IOS8中使用UIAlertController创建警告窗口
1.IOS8中使用UIAlertController创建警告窗口 #pragma mark - 只能在IOS8中使用的,警告窗口- (void)showOkayCancelAlert{ NSSt ...
- iOS:提示框(警告框)控件UIActionSheet的详解
提示框(警告框)控件2:UIActionSheet 功能:当点击按钮或标签等时,弹出一个提示框,显示必要的提示,然后通过添加的按钮完成需要的功能.它与导航栏类似,它继承自UIView. 风格类型: ...
- SweetAlert-js超酷消息警告框插件
简要教程 SweetAlert是一款神奇的javascript弹出消息警告框插件. 来通过一张gif图片看看SweetAlert的效果: 使用方法 要使用该插件,首先要在html的header中引入以 ...
- selenium+webdriver+python 中警告框的处理方法
在自动化测试过程中,经常会遇到弹出警告框的情况,如图所示: 在 WebDriver 中处理 JavaScript 所生成的 alert.confirm 以及 prompt 是很简单的.具体做法是使用 ...
- Bootstrap 弹出框和警告框插件
一.弹出框 弹出框即点击一个元素弹出一个包含标题和内容的容器. //基本用法 <button class="btn btn-lg btn-danger" type=" ...
- bootstrap-巨幕、缩略图、警告框
巨幕: <div class="jumbotron"> <div class="container"> <h1>W3Scho ...
- Bootstrap 巨幕页头缩略图和警告框组件
一.巨幕组件 //在固定的范围内,有圆角 <div class="container"> <div class="jumbotron"> ...
- ios9 之后,Xcode7不推荐使用UIAlertView,改用UIAlertController+UIAlertAction(按钮)
/** * ios9 之后,Xcode7不推荐使用UIAlertView,改用UIAlertController+UIAlertAction(按钮) */ UIAlertController *al ...
随机推荐
- genymotion启动虚拟机遇到问题解决方法步骤
通过在不做任务设置时启动genymotion,会遇到一些问题: 会弹出类似如下问题: 要解决这样问题,首先要知道是什么问题,一般按提示在VitualBox中启动虚拟机就可以知道是什么问题. “To f ...
- C# 一些知识点总结(二)_路径类,编码类,文件类...
Path 类:路径类path.GetFileName("文件路径")//获取完整文件名,包括文件名和文件拓展名Path.GetFileNameWithoutExtension(&q ...
- python 字符编码 转换
#!/bin/env python#-*- encoding=utf8 -*-# 文件头指定utf8编码还是乱码时,使用下面方式指定# fix encoding problem import sys ...
- MySQL的btree索引和hash索引的区别
Hash 索引结构的特殊性,其检索效率非常高,索引的检索可以一次定位,不像B-Tree 索引需要从根节点到枝节点,最后才能访问到页节点这样多次的IO访问,所以 Hash 索引的查询效率要远高于 B-T ...
- The CLR's Thread Pool
We were unable to locate this content in zh-cn. Here is the same content in en-us. .NET The CLR's Th ...
- 大毕设-MATLAB-常用知识回顾
要用到FIR滤波器和抽样器下面研究这两个的Matlab实现: Fir滤波器: matlab上fir滤波器的关键字是fir1 在command窗口输入help fir1出现帮助文档: >> ...
- Android_Activity生命周期
通过前面一段时间的学习,我们很清楚我们的一系列操作都离不开的一个东西,就是我们的activity .接下来我们对 Activity 进行系统的总结. Activity 的四种基本状态 1.运行态(Ru ...
- 【Python全栈笔记】04 [模块二] 18 Oct lambda表达式, 内置函数
lambda表达式 lambda表达式是函数的一种简化,如下面两种函数定义方法,实际上效果是一样的. 使用lambda表达式的函数,func2是函数名,lambda: 后面的123 即为返回值. de ...
- [2015hdu多校联赛补题]hdu5384 Danganronpa
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5384 题意:函数f(A, B)定义:A.B为字符串,f(A, B)为A中有多少个不同的B(ex:f(& ...
- HUST 1017 - Exact cover (Dancing Links 模板题)
1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...