zhuimengFIRE
7/20/2017 - 3:12 AM

alert

alert

- (void)showAlert 
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"title" message:@"choose images from Photo Library" preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            [self loadImagePickerControllerWithType:UIImagePickerControllerSourceTypeCamera];
        }else {
            NSLog(@"您的设备不支持拍照功能");
        }
    }];
    
    UIAlertAction *chooseAction = [UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
            [self loadImagePickerControllerWithType:UIImagePickerControllerSourceTypePhotoLibrary];
        }else {
            NSLog(@"您的设备不支持相册功能");
        }
    }];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    
    [alert addAction:cameraAction];
    [alert addAction:chooseAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:nil];
}