ios警告与提示对话框

  进行iOS开发过程中,不可避免的使用到各种提醒,来提醒用户当前操作,或是为了警告,或是为了数据缓冲。

  本文介绍了使用 UIAlertController和UIAlertAction两个类,完成三种状态的提醒。

这里首先使用UIAlertController创建一个提示对话框,按照工厂方法即可快速创建,参数UIAlertControllerStyle只有一种样式:UIAlertControllerStyleAlert。

填写完提示的标题和内容后,就可以使用UIAlertAction创建一个具体的按钮行为了。参数UIAlertActionStyle有三种样式, UIAlertActionStyleDefault(普通)、UIAlertActionStyleCancel(取消)、UIAlertActionStyleDestructive(警告(破坏性的))。默认状态是正常蓝色字体,取消状态时字体加粗,而警告状态字体则会变为红色。当只添加一个行为对象时,行为对象会显示在UIAlertController对象的下面,添加2个时,并排显示,添加3个及以上者,按列显示。

  你可以很方便的在任意一个事件响应函数中,添加以下代码,并在块语句中添加当用户选择相应的选项时执行的语句。

    //使用UIAlertController创建一个提示对话框,只有标题和信息
    //UIAlertControllerStyle只有一种样式:UIAlertControllerStyleAlert

    //使用UIAlertAcion创建具体的行为,同时添加三个则按列显示
    //UIAlertActionStyle有三种样式,普通、取消、警告(破坏性的)
    //UIAlertActionStyleDefault、UIAlertActionStyleCancel(字体加粗显示)、UIAlertActionStyleDestructive(字体红色显示)

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"messagebox" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    }];
    UIAlertAction *action2= [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    }];
    UIAlertAction *action3= [UIAlertAction actionWithTitle:@"警告" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
    }];

    [alert addAction:action1];
    [alert addAction:action2];
    [alert addAction:action3];
    [self presentViewController:alert animated:YES completion:^{
    }];
时间: 2024-05-07 00:26:06

ios警告与提示对话框的相关文章

WinForm MessageBox 提示对话框

public class MessageUtil { /// <summary> /// 显示一般的提示信息 /// </summary> /// <param name="message">提示信息</param> public static DialogResult ShowTips(string message) { return MessageBox.Show(message, "提示信息",MessageBo

Ext信息提示对话框

Ext.window.MessageBox是一个工具类,他继承自Ext.window.Windoe对象,用来生成各种风格的信息提示对话框,其实例对象可以通过Ext.MessageBox或Ext.Msg进行访问,使用Ext.MessageBox和使用Ext.Msg有相同的效果,而后者提供了更简短的调用方式.为了描述方便后边我们将使用Ext.MessageBox代表Ext.window.MessageBox实例对象. /** **Ext.MessageBox和Ext.Msg只是引用了Ext.wind

iOS Swift WisdomHUD 提示界面框架

iOS Swift WisdomHUD 提示界面框架  Framework Use profile(应用简介) 一:WisdomHUD简介 今天给大家介绍一款iOS的界面显示器:WisdomHUD,WisdomHUD是Swift 4.2编写的framework,支持iOS8.0及以上使用,并且完成兼容OC项目的调用, 使用方便,支持动态属性可设置. 二:WisdomHUD集成 1. pod集成:pod  'WisdomHUD' 2. github链接地址:https://github.com/t

java基础--提示对话框的使用

java基础--提示对话框的使用 2019-03-17-00:35:50-----云林原创 一.显示信息对话框:使用“JOptionPane.showMessageDialog”显示:   图标 对话框类型 语法 显示错误类型对话框 showMessageDialog(null,"这是内容,显示错误","标题",JOptionPane.ERROR_MESSAGE); 传达信息类型对话框 showMessageDialog(null, "这里是传达信息的信息

ios 警告

#import <SystemConfiguration/SystemConfiguration.h> #import <MobileCoreServices/MobileCoreServices.h> ios 警告,布布扣,bubuko.com

bootstrap错误警告信息提示

bootstrap提供了成功执行.警告和错误信息的样式. 在使用该功能的时候需要引入以下几个文件: bootstrap.css jquery.js(需放在bootstrap.js之前) bootstrap.js(官方推荐引入的是bootstrap-alert.js) 主要使用的样式: .span4 .alert(默认样式) .alert alert-successs .alert alert-error .alert alert-info 实例代码如下: <!DOCTYPE html> <

简单封装MessageBox提示对话框

namespace DMS.Common { public class MsgHelper { public static DialogResult ShowErrorMsgBox(string error) { return MessageBox.Show(error, "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } public static DialogResult ShowInformationMsgBox(str

关于提示对话框的总结

---恢复内容开始--- 安卓的对话框有两种:PopupWindow和AlterDialog 它们的不同点在于:AlterDialog的位置固定(提示对话框:ps暂且自己先这样理解),而PopupWindow的位置可以随意(逐渐显示出来的窗口 :ps也是按照自己理解来吧) AlertDialog需要建立一个创建者AlertDialog.Builder bulider AlertDialog.Builder bulider=new AlertDialog.Builder(AlertActivity

自动更新--下载apk以及提示对话框的实现(3)

下载apk以及提示对话框的实现 一.步骤: 1. 确定有可以更新的版本,对话框提醒用户是否进行更新. 2. 选择更新的话,显示下载对话框并且进行下载,否则关闭提示更新对话框. 3. Apk下载完成后,安装apk. 二.具体细节: 1. 提示用户更新的时候,实现必须更新的方法如下:显示的对话框只显示更新按钮,也就是只能选择更新. 2. 下载的时候,下载对话框的页面显示一个进度条来显示下载进度. 3. 下载的时候,启动一个子线程来进行下载. 4. 下载的时候需要来源路径和下载后保存的路径. 5. 下