您的位置:首页 > 移动开发 > IOS开发

iOS9 提示框的使用

2016-01-18 15:38 501 查看
在从iOS8到iOS9的升级过程中,弹出提示框的方式有了很大的改变,在Xcode7 ,iOS9.1的SDK中,已经明确提示不再推荐使用UIAlertView,而只能使用UIAlertController,我们通过代码来演示一下。

UIImagePickerController * picker = [[UIImagePickerController
alloc] init];
    picker.delegate =
self;
    //初始化提示框;
    UIAlertController * alert = [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:  UIAlertControllerStyleActionSheet];
    
    [alert addAction:[UIAlertAction
actionWithTitle:@"拍照"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *
_Nonnull action) {
        //点击按钮的响应事件;
        if ([UIImagePickerController
isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            picker.sourceType =
UIImagePickerControllerSourceTypeCamera;
            
        }else{
            NSLog(@"模拟器无法打开相机");
        }
        [self
presentViewController:picker
animated:YES
completion:nil];
    }]];
    [alert addAction:[UIAlertAction
actionWithTitle:@"相册"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *
_Nonnull action) {
        //点击按钮的响应事件;
        picker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
        [self
presentViewController:picker
animated:YES
completion:nil];
    }]];
    
    [alert addAction:[UIAlertAction
actionWithTitle:@"取消"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *
_Nonnull action) {
        //点击按钮的响应事件;
    }]];
    //弹出提示框;
    [self
presentViewController:alert
animated:true
completion:nil];
          


//初始化提示框;

    UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:  
UIAlertControllerStyleAlert];

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  foundation ios 提示框