Dashboard是一个UINavigationController作为根视图控制器。我在AppDelegate中添加了一些行以使其透明:
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)
当我从Dashboard推动视图控制器时,将视图控制器导航栏颜色更改为黑色。
我想要与仪表板导航栏相同的外观。我已经回答了问题。但仍然没有运气。
答案 0 :(得分:0)
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.
答案 1 :(得分:0)
完整的透明导航栏
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
您甚至可以将此代码用于基类,并将其继承到透明导航栏。