iOS开发类似微信上传头像小操作Demo
2015-11-27 14:58
573 查看
效果图:
代码:
图片选择器前面的tablvew里的东西- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // 图片选择器 UIImagePickerController *imgPC = [[UIImagePickerController alloc] init]; //设置代理 imgPC.delegate = self; //允许编辑图片 imgPC.allowsEditing = YES; if (indexPath.row == 0) { NSLog(@"从手机相册选择图片"); //图片库 imgPC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){ //显示控制器 [self presentViewController:imgPC animated:YES completion:nil]; }else{ [SVProgressHUD showInfoWithStatus:@"请允许程序打开相册"]; } }else if(indexPath.row == 1){ NSLog(@"拍照"); //拍照 imgPC.sourceType = UIImagePickerControllerSourceTypeCamera; //显示控制器 if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ //显示控制器 [self presentViewController:imgPC animated:YES completion:nil]; }else{ [SVProgressHUD showInfoWithStatus:@"请允许程序运行拍照功能"]; } } }
选择好图片后在相册或者照相后的图片右下角选择图片按钮点击
#pragma - mark 图片选择成功后的代理 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info { NSLog(@"info== %@",info); //获取修改后的图片 UIImage *editedImg = info[UIImagePickerControllerEditedImage]; self.iconView.image = editedImg; [self dismissViewControllerAnimated:YES completion:nil]; }
相关文章推荐
- 社交巨头三国杀:微信、WhatsApp、Line到底有啥区别?
- Android Native 绘图方法
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 微信悄悄升级群聊功能:个人微信营销号的福音
- 我是运营,我没有假期
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- 如何做到日消息量100万的微信公众号?
- 论微信取消推送功能的可能性(原创)
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- 微信的成功,靠的是QQ导流吗?
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 微信服务号推送模板消息接口
- C#中struct和class的区别详解
- VBS ArrayList Class vbs中的数组类