UIAlertView简介

UIAlertView是警告框。


创建警告框:

1.初始化:

- (instancetype)initWithTitle:(NSString *)title
                      message:(NSString *)message
                     delegate:(id)delegate
            cancelButtonTitle:(NSString *)cancelButtonTitle
            otherButtonTitles:(NSString *)otherButtonTitles,
title设置标题字符串,在参数message中设置具体的警告信息,然后在otherButtonTitles中设置按钮标题字符串(以逗号分隔的数组形式进行设置,最后必须以nil结束),delegate设置代理,cencelButtonTitle设置取消按钮。


设置属性:

2.设置代理:

@property(nonatomic, assign) id delegate

3.设置显示风格:

@property(nonatomic, assign) UIAlertViewStyle alertViewStyle
typedef enum {
   UIAlertViewStyleDefault  = 0,
   UIAlertViewStyleSecureTextInput ,
   UIAlertViewStylePlainTextInput ,
   UIAlertViewStyleLoginAndPasswordInput 
} UIAlertViewStyle;

4.设置标题字符串:

@property(nonatomic, copy) NSString *title

5.设置具体的警告消息:

@property(nonatomic, copy) NSString *message

6.是否显示:

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


配置按钮:

7.添加按钮:

- (NSInteger)addButtonWithTitle:(NSString *)title

8.按钮数量:

@property(nonatomic, readonly) NSInteger numberOfButtons

9.返回指定索引按钮的title:

- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex

10.返回指定索引的文本字段:

- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex

11.取消按钮的索引:

@property(nonatomic) NSInteger cancelButtonIndex

12.第一个其他按钮的索引:

@property(nonatomic, readonly) NSInteger firstOtherButtonIndex


显示:

13.显示:

- (void)show

取消:

14.关闭警告框:

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex
                             animated:(BOOL)animated
需要在其第一个参数中指定被触摸按钮的索引值,如果是取消动作的时候,传入cancelButtonIndex属性值。



UIAlertViewDelegate代理:

应对措施:
1.按钮被触摸时:

- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex
当按钮被触摸时,将调用此delegate的这个方法。


定制行为:

2.编辑任何默认的字段添加的风格之后调用:

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView

3.警告框被显示前调用:

- (void)willPresentAlertView:(UIAlertView *)alertView

4.警告框显示后被调用:

- (void)didPresentAlertView:(UIAlertView *)alertView

5.警告框关闭前被调用:

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

6.警告框关闭后悔调用:

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


取消:

7.警告显示中强制关闭时被调用:

- (void)alertViewCancel:(UIAlertView *)alertView
例如警告框显示时应用程序突然关闭等场合。触摸取消按钮是不调用此方法。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值