1

I've a view with nothing but a map on it, inside a navigation controller.

The navigation bar is translucent so the map can be seen slightly through it.

This works fine with the navigation bar tint set to Default, but as soon as I change the bar tint to a specific colour the navigation bar background turns completely transparent.

Interestingly, the issue doesn't happen in the emulator, only on an actual iPhone (a 4 (not S), in case that might be relevant).

I've added no code yet- everything I've put together was generated purely in Interface Builder.

Does anyone have any idea what might be happening here and what I might be doing wrong? Or is this a bug I need to report to Apple?

bcl
  • 478
  • 1
  • 5
  • 16

1 Answers1

1

You need to set the bar's translucent property to true. From the Apple documentation for UINavigationBar:

barTintColor

The tint color to apply to the navigation bar background.
This color is made translucent by default unless you set the translucent property to NO.

When you set a tint color on a UINavigationBar, it sets translucent to false. Unfortunately, translucent can not be set on an appearance proxy. You'll need to add self.navigationController.navigationBar.translucent = YES in all your viewWillAppear: methods (or create your own subclass that changes the default)

wombat57
  • 1,341
  • 1
  • 13
  • 26
  • I added the self.navigationController.navigationBar.translucent = YES; into my viewWillAppear method of the view controller and that sorted it thanks. Unfortunately, I then tried to scale this approach up to a tableview with a map in it. Once again, the navigation bar background becomes transparent as soon as a cell with a map in it is in the tableview. Any suggestions? – bcl Oct 18 '13 at 13:33
  • I don't understand what you are saying. Do you want the navbar on the tableview to be translucent, or not? – wombat57 Oct 18 '13 at 16:56
  • This seems to be a known bug in iOS 7, unrelated to your original question. Here's a previous discussion: http://stackoverflow.com/questions/18917888/mkmapview-makes-the-navigation-bar-gets-transparent – wombat57 Oct 18 '13 at 16:59
  • Sorry- I didn't explain myself so well in my reply, did I? Yes, I was wanting the navbar that sits above the tableview (with the map in it) to be translucent. I appreciate the original question does not appear to be related but it was actually my simplification (i.e. removing the tableview) of exactly the issue you've handily linked to. Thanks for assuring me this isn't down to something dumb I've done but appears to be a bug after all. – bcl Oct 18 '13 at 19:16
  • For anyone else trying to find a way around this, I found this very elegant solution that subclasses the navigation controller and navigation bar to create the exact same effect reliably without requiring any code changes: http://stackoverflow.com/questions/18897485/achieving-bright-vivid-colors-for-an-ios-7-translucent-uinavigationbar?rq=1 – bcl Oct 19 '13 at 16:36