美文网首页
UIImagePickerController 打开相册, 右边

UIImagePickerController 打开相册, 右边

作者: 京北磊哥 | 来源:发表于2019-12-02 14:56 被阅读0次

    废话少说, 直接 上代

    /// 打开相册
    
    -(void)usePhoto{
    
        UIImagePickerController *imagePicker = self.imagePickerController;
    
        //允许编辑
    
        imagePicker.allowsEditing = true;
    
        //设置图片源
    
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    
        imagePicker.delegate = self;
    
        //模态弹出IamgePickerView
    
        [self presentViewController:imagePicker animated:YES completion:^{
    
            UIViewController *contr = imagePicker.viewControllers.lastObject;
    
            UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
            [rightBtn setTitle:@"取消" forState:UIControlStateNormal];
    
            [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
            rightBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    
            [rightBtn sizeToFit];
    
            [rightBtn addTarget:self action:@selector(cancelChioseAction) forControlEvents:UIControlEventTouchUpInside];
    
            UIView *rightView = [[UIView alloc] initWithFrame:rightBtn.bounds];
    
            [rightView addSubview:rightBtn];
    
            UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightView];
    
            contr.navigationItem.rightBarButtonItem = rightItem;
    
        }];
    
    }
    
    ///放弃选择图片
    
    - (void)cancelChioseAction{
    
        [self dismissViewControllerAnimated:YES completion:nil];
    
    }
    

    相关文章

      网友评论

          本文标题:UIImagePickerController 打开相册, 右边

          本文链接:https://www.haomeiwen.com/subject/ikqfgctx.html