UIAlertController和UIImagePickerController的使用

来源:互联网 发布:锐捷网络待遇怎么样 编辑:程序博客网 时间:2024/06/04 19:19

UIAlertController 解释:下拉菜单
UIImagePickerController 解释:照片选取器


1.UIAlertController

//1.声明UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];//2.增加一行按钮[alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)    {//点击按钮相应        NSLog(@"拍照"    );//3.显示[self presentViewController:alert  animated:YES completion:nil];

2.UIImagePickerController

//1.包含代理< UIImagePickerControllerDelegate>//2.声明(可显示)UIImagePickerController *imagePick = [[UIImagePickerController alloc]init]; [self presentViewController:imagePick animated:YES completion:nil];  //3.设置 imagePick.allowsEditing = YES;    //图片可点击 imagePick.delegate = self;            // 委托代理//4.代理函数(选中相片后执行的操作)- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{//将UIImageView上的视图设为自己选择的图片    [self.mainImageView setImage:image];//隐藏此视图    [self dismissViewControllerAnimated:YES completion:nil];}
0 0
原创粉丝点击