Jinah Adam Jinah Adam - 1 year ago 89
Swift Question

UINavigationBar set Background, and set translucent not working

I am trying to set the background and trasparecy for UINavigation bar in code, in the ViewWillAppear func. however it doesn't seem to be working.

self.navigationController!.navigationBar.translucent = false
self.navigationController!.navigationBar.backgroundColor = UIColor.blackColor()

the view controller is load via the storyboard id

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier(storyboardId)
vc.title = storyboardId
let navigationController = UINavigationController(rootViewController: vc)
self.presentViewController(navigationController, animated: false, completion: nil)

i have tried setting it there too, doesn't seem to be working.

additionally i tried with UINavigationBar.appearance() to set the properties, this too doesn't work.


You can try with this:

self.navigationController?.barTintColor = UIColor.blackColor()