iOS 学习

2.UIImagePickerController导航栏背景颜色

2017-12-20  本文已影响64人  峰子1994

1在我们的项目中会经常使用到UIImagePickerController这样我们必须要同意导航栏的颜色

第一种:导航栏颜色:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//1.设置导航栏背景颜色 使用rgb
picker.navigationBar.barTintColor = [UIColor colorWithRed:20.f/255.0 green:24.0/255.0 blue:38.0/255.0 alpha:1];
//设置右侧取消按钮的字体颜色
picker.navigationBar.tintColor = [UIColor whiteColor];
// 2.使用图片
//设置导航栏背景颜色
[imagePickerController.navigationBar  setBackgroundImage:[UIImage imageNamed:@"导航栏"] forBarMetrics:UIBarMetricsDefault];

第二种:统一文字的颜色和样式

UIImagePickerController 继承自 UINavigationController, 需求要设置统一的字体颜色.
百度之后, 试了多种颜色也没有解决.后来想到有一个方法可以设置系统统一的样式: UIAppearance这个协议.
凡是遵守这个协议的都可以在AppDelegate中统一设置整个系统的颜色. 但是不要和UIAppearanceContainer搞混了, UIAppearanceContainer协议下没有声明任何方法.

设置UIBarButtonItem和UINavigationBar的默认文字颜色
[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
[[UINavigationBar appearance] setTitleTextAttributes:attrs];

这样就可以随意设置 UIImagePickerController 导航条的样式了
上一篇下一篇

猜你喜欢

热点阅读