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

后端 未结 7 1627
野的像风
野的像风 2021-02-02 09:48

What is the correct way to color the UIImagePickerController\'s nav bar?
I merely tried to see the background color but I\'m getting a faded color as seen in the image bel

相关标签:
7条回答
  • 2021-02-02 10:17

    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()
         ]
    
    }
    
    0 讨论(0)
  • 2021-02-02 10:22

    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

    0 讨论(0)
  • 2021-02-02 10:23

    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.

    0 讨论(0)
  • 2021-02-02 10:27

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

    0 讨论(0)
  • 2021-02-02 10:28

    Swift 5 / IOS 13

    I have found this solution:

    let barApperance = UINavigationBar.appearance()
    barApperance.tintColor = .systemBlue
    

    just put it where you create the UIImagePickerController()

    0 讨论(0)
  • 2021-02-02 10:30

    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:

    0 讨论(0)
提交回复
热议问题