0
votes

Dashboard is a UINavigationController as root view controller. I put some lines in AppDelegate to make it transparent:

let barAppearace = UIBarButtonItem.appearance()
barAppearace.setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -400), forBarMetrics:UIBarMetrics.Default)
barAppearace.setTitleTextAttributes(["NSFontAttributeName":UIFont.customFontOfSize(14, style: FontName.kHelveticaNeue)], forState: .Normal)
barAppearace.tintColor = UIColor.whiteColor()

UINavigationBar.appearance().backgroundColor = UIColor.clearColor()
UINavigationBar.appearance().barTintColor = UIColor.clearColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)

Homepage navigationbar having transparent navigation bar.

when I push a view controller from Dashboard, pushed view controller navigation bar color changes to black.

pushed view controller navigation bar

I want same appearance as Dashboard navigationbar. I have gone through already answered question. But still no luck.

2
add some code. How u r trying to change color?McDonal_11
see this once may be it helps you : stackoverflow.com/questions/25845855/…Anbu.Karthik
On Dashboard screen its working fine. But when I push a view controller from Dashboard screen. The newly pushed controller navbar color changes to black.Sandeep Ahuja
else show your codeAnbu.Karthik
@Anbu.karthik Edited Question and included the code also.Sandeep Ahuja

2 Answers

1
votes

For complete transparent Navigation bar

self.navigationController.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController.navigationBar.shadowImage = UIImage()
self.navigationController.navigationBar.isTranslucent = true
self.navigationController.navigationBar.backgroundColor = .clear
self.navigationController.view.backgroundColor = .clear

You can even use this code for a base class and inherit it for transparent navigation bar.

0
votes
let barAppearace = UIBarButtonItem.appearance()
barAppearace.setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -400), forBarMetrics:UIBarMetrics.Default)
barAppearace.setTitleTextAttributes(["NSFontAttributeName":UIFont.customFontOfSize(14, style: FontName.kHelveticaNeue)], forState: .Normal)
barAppearace.tintColor = UIColor.whiteColor()

UINavigationBar.appearance().backgroundColor = UIColor.clearColor()
UINavigationBar.appearance().barTintColor = UIColor.clearColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)

I put a background image in view controller and applied below constraints to it. I achieved the desired result:

backgroundImage.centerX = view.CenterX
backgroundImage.centerY = view.CenterY
backgroundImage.height = view.height
backgroundImage.width = view.width

* view: Managed by viewcontroller property view.
* backgroundImage: subview added to view with above constraints.