UIImagePickerController 打开相册, 右边

2019-12-02  本文已影响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];

}
上一篇下一篇

猜你喜欢

热点阅读