天天看點

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起失效)

繼續閱讀