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

效果图:

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];
}

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

上一篇:“小习惯”小程序需求规格说明书


下一篇:南通大学教务管理微信公众号的用户体验