AI智能
改变未来

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:^{}];}
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » IOS开发控件视图day04:Alert弹窗调出相册相机