更改系统相机UIImagePickerController导航栏的cancle为自定义按钮

有时候需要对系统相册里面的取消按钮进行自定义,并获取点击事件做一些操作,那么你可以这样做。

 

第一:实现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];

}

 

posted @ 2016-07-05 11:03  有梦想的人,不睡觉  阅读(4801)  评论(0编辑  收藏  举报