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

效果图:

这里写图片描述

代码:

图片选择器前面的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];
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值