有时候需要对系统相册里面的取消按钮进行自定义,并获取点击事件做一些操作,那么你可以这样做。
第一:实现navigationController代理
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
UIButton *cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(0,0,50,30)];
[cancelBtn setTitle:@"取消" forState:(UIControlStateNormal)];
cancelBtn.backgroundColor = [UIColor redColor];
[cancelBtn addTarget:self action:@selector(click) forControlEvents:(UIControlEventTouchUpInside)];
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:cancelBtn];
[viewController.navigationItem setRightBarButtonItem:btn animated:NO];
}
第二:实现click方法即可完成;self.imagePicker为弱引用
@property (nonatomic, weak) UIImagePickerController *imagePicker;
- (void)click{
//做你需要做的事情
[self imagePickerControllerDidCancel:self.imagePicker];
}