天天看点

UIAlertView常用属性(9.0起失效)

UIAlertView的继承关系:

UIAlertView:UIView:UIResponder:NSObject

- (void)viewDidLoad
{
    [super viewDidLoad];

    /**
     1、初始化

     - initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:
     */
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示框"
                                                       message:@"这是我测试的一个提示框"
                                                      delegate:self
                                             cancelButtonTitle:@"取消"
                                             otherButtonTitles:@"确定", nil];


    /**
     2、设置属性

         .alertViewStyle    //设置类型  UIAlertViewStyleDefault默认、 
                                                       SecureTextInput密码输入框、
                                                       PlainTextInput普通输入框、
                                                       LoginAndPasswordInput账号密码框
         .title             //设置标题
         .message           //设置消息
         .visible           //获取是否显示,判断控件是否显示 (只读属性)
     */
    alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    NSLog(@"title:%@",  alertView.title);
    NSLog(@"message:%@",alertView.message);
    NSLog(@"visible:%d",alertView.visible);


    /**
     3、配置按钮

         - addButtonWithTitle:  //添加新的按钮

         - buttonTitleAtIndex:  //根据索引,获取按钮的标题
         - textFieldAtIndex:    //根据索引,获取文本输入框的内容

         .numberOfButtons       //总的按钮数
         .cancelButtonIndex     //取消按钮的index
         .firstOtherButtonIndex //第一个其他按钮的index
     */
    [alertView addButtonWithTitle:@"完成"];

    NSLog(@"buttonTitleAtIndex:%@",     [alertView buttonTitleAtIndex:]);

    NSLog(@"numberOfButtons:%d",        alertView.numberOfButtons);
    NSLog(@"cancelButtonIndex:%d",      alertView.cancelButtonIndex);
    NSLog(@"firstOtherButtonIndex:%d",  alertView.firstOtherButtonIndex);


    /**
     4、显示

         - show
     */
    [alertView show];

    /**
     5、回收AlertView

         - dismissWithClickedButtonIndex:animated:
     */


    /**
     6、代理

         .delegate

         - alertView:clickedButtonAtIndex:          //点击按钮时触发的方法

         - alertViewShouldEnableFirstOtherButton:   //设置是否允许第一个按钮不是取消按钮

         - willPresentAlertView:                    //将要展现警告框时触发的方法
         - didPresentAlertView:                     //已经展现警告框时触发的方法

         - alertView:willDismissWithButtonIndex:    //警告框将要消失时触发的方法
         - alertView:didDismissWithButtonIndex:     //警告框已经消失时触发的方法

         - alertViewCancel:                         //alertView消失前要执行的行为。
     */

}
           
UIAlertView常用属性(9.0起失效)
UIAlertView常用属性(9.0起失效)