0
votes

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

1
A quick search in SO would give you a lot of results on this topic. Take a look at this link, stackoverflow.com/questions/20319439/… - R P
Ty for reply. I have already tried that in my viewController and appDelegate, but the result is the same as in the picture! - Stav1
Please provide the code, so that it would be easier to debug. - R P
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
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

1 Answers

0
votes

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