码迷,mamicode.com
首页 > 微信 > 详细

iOS开发类似微信上传头像小操作Demo

时间:2015-11-27 17:46:01      阅读:361      评论:0      收藏:0      [点我收藏+]

标签:

效果图:

技术分享

代码:

图片选择器前面的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];
}

iOS开发类似微信上传头像小操作Demo

标签:

原文地址:http://blog.csdn.net/u013357243/article/details/50070325

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!