IOS中UIAlertView(警告框)常用方法总结

一、初始化方法

- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(NSString*)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...;

这个方法通过设置一个标题,内容,代理和一些按钮的标题创建警告框,代码示例如下:

1
2
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"我的警告框" message:@"这是一个警告框" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alert show];

效果如下:

注意:如果按钮数超过两个,将会创建成如下样子:

如果按钮数量超出屏幕显示范围,则会创建类似tableView的效果。

二、属性与方法解析

标题属性

@property(nonatomic,copy) NSString *title;

内容属性

@property(nonatomic,copy) NSString *message;

添加一个按钮,返回的是此按钮的索引值

- (NSInteger)addButtonWithTitle:(NSString *)title;

返回根据按钮索引按钮标题

- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;

获取按钮数量

@property(nonatomic,readonly) NSInteger numberOfButtons;

设置将某一个按钮设置为取消按钮

@property(nonatomic) NSInteger cancelButtonIndex;

返回其他类型按钮第一个的索引值

@property(nonatomic,readonly) NSInteger firstOtherButtonIndex;

警告框是否可见

@property(nonatomic,readonly,getter=isVisible) BOOL visible;

显现警告框

- (void)show;

代码模拟点击按钮消失触发方法

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;

设置警告框风格

@property(nonatomic,assign) UIAlertViewStyle alertViewStyle;

风格的枚举如下

1
2
3
4
5
6
typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
    UIAlertViewStyleDefault = 0,//默认风格
    UIAlertViewStyleSecureTextInput,//密码输入框风格
    UIAlertViewStylePlainTextInput,//普通输入框风格
    UIAlertViewStyleLoginAndPasswordInput//账号密码框风格
};

这个方法设置文本输入框的索引

- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex;

三、UIAlertViewDelegate中的方法

点击按钮时触发的方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

将要展现警告框时触发的方法

- (void)willPresentAlertView:(UIAlertView *)alertView;

已经展现警告框时触发的方法

- (void)didPresentAlertView:(UIAlertView *)alertView;

警告框将要消失时触发的方法

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex;

警告框已经消失时触发的方法

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;

设置是否允许第一个按钮不是取消按钮

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView;

辅助功能:UIAlertViewStyle的类型:

    UIAlertViewStyleDefault = 0:一个标准的警告框

UIAlertViewStyleSecureTextInput, :一个能够让用户输入文本的警告框,并且文本框是掩盖的

UIAlertViewStylePlainTextInput, :一个能够让用户 输入文本的警告框

UIAlertViewStyleLoginAndPasswordInput :一个能够让用户输入账号和密码的警告框

UIkit框架之UIalert(iOS 9之后就不用这个了)的更多相关文章

  1. iOS学习32之UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  2. iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。

    转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...

  3. iOS开发UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  4. 79、iOS 的Cocoa框架、Foundation框架以及UIKit框架

    Cocoa框架是iOS应用程序的基础 1. Cocoa是什么? Cocoa是 OS X和ios 操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发 ...

  5. 基础框架Fundation和UIkit框架的定义和使用

    Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...

  6. ios UIKit动力 分类: ios技术 2015-07-14 12:55 196人阅读 评论(0) 收藏

    UIkit动力学是UIkit框架中模拟真实世界的一些特性. UIDynamicAnimator 主要有UIDynamicAnimator类,通过这个类中的不同行为来实现一些动态特性. 它一般有两种初始 ...

  7. iOS-学习UIKIt框架的重要性

      前言: 众所周知,我们的移动设备的屏幕上可以展示很多图形界面,作为用户的我们可以通过屏幕上的图形界面浏览信息,也可以通过与图形界面的简单交互,在移动设备上实现各种各样的功能操作.....可以说,没 ...

  8. 让Playground支持UIKit框架

    http://blog.diveinedu.cn/playground_uikit_ios/ 让Playground支持UIKit框架 发表于 作者 排云鹤 — 暂无评论 ↓ Xcode 6新增了Pl ...

  9. Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)

    原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...

随机推荐

  1. python读取指定内存的内容

    import ctypes as ct t = ct.string_at(0x211000, 20) # (addr, size) print t 最好不要用解释性语言来开发底层,一般用C.

  2. PHP Warning: ob_start() : output handler 'ob_gzhandler conflicts with 'zlib output compression'

    安装phpcms过程中,会遇到Warning:  ob_start() : output handler 'ob_gzhandler conflicts with 'zlib output compr ...

  3. 修改Linux系统时区

    修改配置文件来修改时区1.修改/etc/sysconfig/clock         ZONE=Asia/Shanghai 2.rm /etc/localtime3.链接到上海时区文件 ln -sf ...

  4. Collaborative Filtering

    for i=1:6040 Ai=ratings(ratings(:,1)==i,:); for j=1:5 Labnum(i,j)=length(Ai(Ai(:,3)==j)); end num(i) ...

  5. 采用SHELL,通过SQL LOAD导入一定格式的txt文件至数据库中

    1. 准备工作,window中可直接通过sqlload直接导入文件,linux下,需要有sqlload的相关软件. 2. SQL脚本(MID_DFDZ.ctl) LOAD DATA INTO TABL ...

  6. excel快捷键设置

    Excel技能 按键 结果 序号 Alt+1 合并后居中 1 ALT+2 边框 2 ALT+3 边框线型 3 ALT+4 格式刷 4 ALT+5 清除格式 5 CTRL+SHIFT+P 设置字体 6 ...

  7. 转:Nginx 配置 location 总结及 rewrite 规则写法

    转: http://www.linuxidc.com/Linux/2015-06/119398.htm 1. location正则写法 一个示例: location =/{ # 精确匹配 / ,主机名 ...

  8. EFCode First 导航属性

    首先谈谈自己对EF的接触的过程吧,最先接触EF只是因为EF支持从数据库把关系扒下来,可以省掉自己写Select.Update.Insert这些SQL语句,而且修改非常方便,后来在使用的过程中发现导航属 ...

  9. Icon资源详解[1]

    本文分享&备忘最近了解到的icon资源在windows平台下相关的一部分知识,所有测试代码都尽可能的依赖win32 API实现.更全面的知识,参考文末列出的”参考资料“.      关键字:I ...

  10. 服务器后端开发系列——《实战Memcached内存缓存系统》

    1.实战Memcached缓存系统(1)Memcached基础及示例程序 内容:建筑Memcached背景知识和入门示例程序. 2.实战Memcached缓存系统(2)Memcached Java A ...