Frederick C. Lee
Frederick C. Lee

Reputation: 9493

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

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 below; as if some view is obstructing it.

let picker = UIImagePickerController()
picker.sourceType = type
picker.mediaTypes = [kUTTypeImage]
picker.delegate = self
picker.navigationBar.backgroundColor = UIColor.redColor()

enter image description here

It appears to have some view obscuring the redColor():

(lldb) po picker.navigationBar.subviews
2 values
 {
  [0] = 0x00007fe7bb52a890
  [1] = 0x00007fe7bb52b670
}

What is the correct way to create a solid color for the Navigation Bar?

Upvotes: 29

Views: 22210

Answers (8)

Manish
Manish

Reputation: 702

[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
[[UINavigationBar appearance] setTitleTextAttributes:
    [NSDictionary dictionaryWithObjectsAndKeys:
     [UIColor whiteColor], nil]];

This works for me on iOS 14. Nothing else works.

Upvotes: 0

user13968269
user13968269

Reputation: 71

Swift 5 / IOS 13

I have found this solution:

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

just put it where you create the UIImagePickerController()

Upvotes: 7

Michal
Michal

Reputation: 15669

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:

enter image description here

Upvotes: 58

Boaz Frenkel
Boaz Frenkel

Reputation: 746

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

Upvotes: 3

Mitul Marsoniya
Mitul Marsoniya

Reputation: 5299

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()
     ]

}

Upvotes: 9

hasan
hasan

Reputation: 24205

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

Upvotes: 0

Walter
Walter

Reputation: 306

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]};

Upvotes: 10

rintaro
rintaro

Reputation: 51911

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.

Upvotes: 20

Related Questions