更改系统相机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];

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2026 CODEPRJ.COM