iOS 调用系统照相机后,怎么把照相机的导航栏颜色改掉
2017-03-22 本文已影响66人
bc3d3e66fba3

今天在项目中遇到一个问题,就是在present出系统相册的界面里,出现的导航栏的背景颜色和我当前项目的导航栏的背景颜色不相匹配,那我就需要去修改弹出的系统相册的导航栏的背景颜色。但是,我要怎么去改呢???😭在网上也搜索了相关的问题,有人问这个问题,但是没有几个人解决出来,而且有的人给的答案完全没有解决这个问题,所以自己就想了一想。。。
UIImagePickerController * imagePickerController = [[UIImagePickerController alloc]init];
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePickerController animated:YES completion:^{
}];
在这段代码中,发现了这句话imagePickerController.delegate = self;
于是就点进去看了一下这个代理
@property(nullable,nonatomic,weak) id <UINavigationControllerDelegate, UIImagePickerControllerDelegate> delegate;
有个导航控制器的代理,我想它应该可以去修改导航栏的属性吧!看了一下导航控制器的代理的协议方法:
@protocol UINavigationControllerDelegate <NSObject>
@optional
// Called when the navigation controller shows a new top view controller via a push, pop or setting of the view controller stack.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
- (nullable id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController NS_AVAILABLE_IOS(7_0);
- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC NS_AVAILABLE_IOS(7_0);
@end
在这些协议方法里,我就在使用了这个方法
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
在点击跳转相册的那个界面,设置好这个代理后imagePickerController.delegate = self;,实现这个协议方法
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
UINavigationBar *navigationBar = navigationController.navigationBar;
[navigationBar setBackgroundImage:[self createImageWithColor:rgb(46, 46, 46, 1)] forBarMetrics:UIBarMetricsDefault];
navigationBar.tintColor = [UIColor whiteColor];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
}
这样设置好自己的想要显示的导航栏的背景颜色,就可以正常显示了!!!
今天做不成的,明天也不会做好,一天也不能够虚度。——歌德