How do you color/customize the UIImagePickerController's Navigation Bar?

一个人想着一个人 提交于 2019-12-02 20:20:48
Michal

Updated for Swift 4.2

For completeness, I'll add full color customization setup:

let imagePicker = UIImagePickerController()
imagePicker.navigationBar.isTranslucent = false
imagePicker.navigationBar.barTintColor = .blue // Background color
imagePicker.navigationBar.tintColor = .white // Cancel button ~ any UITabBarButton items
imagePicker.navigationBar.titleTextAttributes = [
        NSAttributedString.Key.foregroundColor: UIColor.white
] // Title color

which results in:

Try:

picker.navigationBar.translucent = false
picker.navigationBar.barTintColor = .redColor()

Instead of

picker.navigationBar.backgroundColor = UIColor.redColor()

If you want translucent effects, leave translucent = true as default.

Here the right solution code in Objective-C. Might be useful.

imagePickerController.navigationBar.translucent = NO;
imagePickerController.navigationBar.barTintColor = [UIColor colorWithRed:0.147 green:0.413 blue:0.737 alpha:1];
imagePickerController.navigationBar.tintColor = [UIColor whiteColor];
imagePickerController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};

Swift = IOS 8 || 9

Just put this method

func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) 
{
     imagePicker.navigationBar.tintColor = .whiteColor()
     imagePicker.navigationBar.titleTextAttributes = [
     NSForegroundColorAttributeName : UIColor.whiteColor()
     ]

}

For Swift, IOS 8-10 As rintaro mentioned, I think the main issue here is changing the default translucent property of the picker navigationBar:

picker.navigationBar.translucent = false

This will cause the the navigation bar to use the UINavigationBar appearance if you set this somewhere in your app.

If you need another color you can use
picker.navigationBar.barTintColor = UIColor.someColor

UIImagePickerController is a UINavigationController. It can be styled as the same way the UINavigationController get styled.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!