IOS开发控件视图day04:Alert弹窗调出相册相机

1、中间弹窗
(1)、标题创建

UIAlertController *aler = [UIAlertController alertControllerWithTitle:@"是否不当人?" message:str preferredStyle:UIAlertControllerStyleAlert];

(2)、选项

UIAlertAction *sureAler = [UIAlertAction actionWithTitle:@"不当了" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *cancelAler = [UIAlertAction actionWithTitle:@"容我再想想" style:UIAlertActionStyleDestructive handler:nil];

(3)、添加到控制器

[aler addAction:cancelAler];
[aler addAction:sureAler];
[self presentViewController:aler animated:YES completion:nil];

1、底部弹窗选择图片
(1)、声明和代理

UIImagePickerController *imagePickerConter = [[UIImagePickerController alloc]init];
imagePickerConter.delegate  = self;//设置代理
imagePickerConter.allowsEditing = YES;//允许编辑图片

(2)、标题

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择图片" message:@"来源" preferredStyle:UIAlertControllerStyleActionSheet];

(3)、选项

    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"相簿" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        imagePickerConter.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:imagePickerConter animated:YES completion:nil];
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        imagePickerConter.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        [self presentViewController:imagePickerConter animated:YES completion:nil];
    }];
    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        imagePickerConter.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:imagePickerConter animated:YES completion:nil];
    }];
    UIAlertAction *canceAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];    

(4)、添加到视图

[alert addAction:action1];
[alert addAction:action2];
[alert addAction:action3];
[alert addAction:canceAction];
[canceAction setValue:[UIColor redColor] forKey:@"titleTextColor"];//设置按钮颜色
[self presentViewController:alert animated:YES completion:nil];//回调

(5)、选择图片

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    if (image == nil) {
        image = [info objectForKey:UIImagePickerControllerOriginalImage];
    }
    self.imageView.image = image;
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

(6)、回调

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值