您的位置:首页 > 移动开发 > 微信开发

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];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息