0

I am just a simple guy struggling to get a translucent navigation bar. I have tried to set it in appDelegate and in the spesific ViewController. What i end up with is this: Does anyone know why the section header in white is moved down? The navigation bar is not even translucent when i scroll and i can´t set a color to it. (i can set color when translucent = false) I have tried to set it to translucent and opaque and inferred in storyboard.(not working)

Update:

let colorImage = imageFromColor(UIColor(red:0.22, green:0.23, blue:0.29, alpha:0.5), frame: CGRectMake(0, 0, 340, 64))
self.navigationController!.navigationBar.setBackgroundImage(colorImage, forBarMetrics: UIBarMetrics.Default)
self.navigationController!.navigationBar.shadowImage = colorImage
self.navigationController!.navigationBar.translucent = true

The colorImage is a image i make with a rgb-uicolor. The outcome is this: navigation bar 2

It is transclucent between the section header, but the top bar is not!

UPDATE 2

Stav1
  • 132
  • 2
  • 11
  • A quick search in SO would give you a lot of results on this topic. Take a look at this link, http://stackoverflow.com/questions/20319439/how-to-make-navigation-bar-transparent-in-ios-7 – R P Dec 02 '15 at 22:55
  • Ty for reply. I have already tried that in my viewController and appDelegate, but the result is the same as in the picture! – Stav1 Dec 02 '15 at 23:03
  • Please provide the code, so that it would be easier to debug. – R P Dec 02 '15 at 23:08
  • override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) self.navigationController!.navigationBar.setBackgroundImage(colorImage, forBarMetrics: UIBarMetrics.Default) self.navigationController!.navigationBar.shadowImage = colorImage self.navigationController!.navigationBar.translucent = true } – Stav1 Dec 02 '15 at 23:14
  • Are you trying to display a custom `shadowImage` for your `navigationBar` or is it only because it was mentioned in the code? Check after commenting out that line of code – R P Dec 03 '15 at 00:12
  • Yes, it was to make it a gray color. It is still the same, just without gray-color. I think I have a case of "Double navigation bars". Maybe I am doing something wrong in the storyboard with the connection between my tabBar controller and the navigation controllers – Stav1 Dec 03 '15 at 00:18
  • To understand your requirement clearly, are you trying to achieve something like the top section in this [image](http://i.stack.imgur.com/ZQzd3.png) – R P Dec 03 '15 at 00:45
  • That is what I want! – Stav1 Dec 03 '15 at 00:49

1 Answers1

0

If you are trying to set a translucent background for navigationBar across your application, you can use the following code in application:didFinishLaunchingWithOptions method of your AppDelegate

let colorImage = getImageWithColor(UIColor(red:0.22, green:0.23, blue:0.29, alpha:0.5), size: CGSizeMake(360, 64))
UINavigationBar.appearance().setBackgroundImage(colorImage, forBarMetrics: UIBarMetrics.Default)
UINavigationBar.appearance().translucent = true
UINavigationBar.appearance().tintColor = UIColor.whiteColor()

Result Screenshot:

enter image description here

R P
  • 1,173
  • 2
  • 11
  • 20