废话少说, 直接 上代码
/// 打开相册
-(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];
}
网友评论