IOS UIAlertView 和 UIActionSheet的區別

來源:互聯網
上載者:User

標籤:

UIAlertView 和 UIActionSheet的區別:

1.彈框位置不同:

UIAlertView彈框顯示在中間

UIActionSheet彈框顯示在底端

2.是否可以實現文字框的輸入(參考:http://www.ithao123.cn/content-9409772.html)

UIAlertView可以實現,而UIActionSheet不可以實現。

#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];}

 

 



IOS UIAlertView 和 UIActionSheet的區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.