欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IOS開(kāi)發(fā) UIAlertController詳解及實(shí)例代碼

 更新時(shí)間:2016年12月23日 11:48:39   投稿:lqh  
這篇文章主要介紹了 IOS開(kāi)發(fā) UIAlertController詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下

 IOS開(kāi)發(fā) UIAlertController詳解

在iOS 8.0后,蘋果棄用了UIAlertView和UIActionSheet,轉(zhuǎn)而使用UIAlertController把之前的UIAlertView和UIActionSheet整合在一起。新版的API變得簡(jiǎn)潔了不少幾行代碼就可實(shí)現(xiàn)之前一大片代碼的功能

 UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"
                                  message:@"This is an alert."
                              preferredStyle:UIAlertControllerStyleAlert];

  UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action) {
                               NSLog(@"你好你好");
                             }];

  UIAlertAction* defaultAction2 = [UIAlertAction actionWithTitle:@"OK2" style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action) {
                               NSLog(@"你好你好");
                             }];

  [alert addAction:defaultAction];
  [alert addAction:defaultAction2];
  [self presentViewController:alert animated:YES completion:nil];

初始化AlertView沒(méi)有太大區(qū)別,主要區(qū)別就是添加事件。蘋果公司新添加了UIAlertAction專門用來(lái)添加事件。一個(gè)Action對(duì)應(yīng)一個(gè)事件,添加到alert上就可以使用。

切換為ActionSheet只需要修改preferredStyle為UIAlertControllerStyleActionSheet

也可以添加輸入框代碼如下

  [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    textField.placeholder = @"輸入用戶名";
  }];



感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論