IOS UIAlertView 和 UIActionSheet的區別

UIAlertView 和 UIActionSheet的區別:html

1.彈框位置不一樣ide

UIAlertView彈框顯示在中間學習

UIActionSheet彈框顯示在底端ui

2.是否能夠實現文本框的輸入(參考:http://www.ithao123.cn/content-9409772.html)spa

UIAlertView能夠實現,而UIActionSheet不能夠實現。code

3.是否能夠實現點擊按鈕事件htm

UIAlertView,UIActionSheet均可以實現對象

用他們的delegate事件處理點擊事件事件

1. UIAlertViewDelegate圖片

#pragma mark UIAlertViewDelegate methods

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

2). UIActionSheetDelegate

#pragma mark UIActionSheetDelegate methods

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

 

 

 



#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // 建立一個BUTTON 點擊顯示彈框 UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)]; button.frame = CGRectMake(100, 100, 100, 100); // 給BUTTON 添加點擊方法 [button addTarget:self action:@selector(actionButton:) forControlEvents:(UIControlEventTouchUpInside)]; button.backgroundColor = [UIColor blueColor]; [self.view addSubview:button]; } // button的點擊方法 - (void)actionButton:(UIButton *)button { // 初始化一個一個UIAlertController // 參數preferredStyle:是IAlertController的樣式 // UIAlertControllerStyleAlert 建立出來至關於UIAlertView // UIAlertControllerStyleActionSheet 建立出來至關於 UIActionSheet UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"靜" preferredStyle:(UIAlertControllerStyleAlert)]; // 建立按鈕 UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"肯定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) { NSLog(@"注意學習"); }]; // 建立按鈕 // 注意取消按鈕只能添加一個 UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) { // 點擊按鈕後的方法直接在這裏面寫 NSLog(@"注意學習"); }]; // // 建立警告按鈕 // UIAlertAction *structlAction = [UIAlertAction actionWithTitle:@"警告" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction *action) { // NSLog(@"注意學習"); // }]; // // 添加按鈕 將按鈕添加到UIAlertController對象上 [alertController addAction:okAction]; [alertController addAction:cancelAction]; //[alertController addAction:structlAction]; // 只有在alert狀況下才能夠添加文本框 [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @"用戶名"; textField.secureTextEntry = YES; }]; // // 取出文本 // UITextField *text = alertController.textFields.firstObject; // UIAlertAction *action = alertController.actions.firstObject; // 將UIAlertController模態出來 至關於UIAlertView show 的方法 [self presentViewController:alertController animated:YES completion:nil]; }

這裏寫圖片描述

相關文章
相關標籤/搜索