转到下一个视图会更改导航栏背景颜色

时间:2017-11-22 07:38:17

标签: ios uiviewcontroller storyboard uinavigationbar

当我使用推送方法呈现新视图时,我的导航栏颜色的一点点移动由于它而变化,它在该门户处显示深蓝色,然后恢复到浅色。

如图所示。

我应该如何解决这个问题

navigation bar background color changes

1 个答案:

答案 0 :(得分:0)

你可以在appdelegate中设置它

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    UINavigationBar.appearance().barTintColor = UIColor(red: 0, green: 0/255, blue: 205/255, alpha: 1)
    UINavigationBar.appearance().tintColor = UIColor.whiteColor()
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]

    return true
}

或可以在viewcontroller中设置

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
self.navigationController?.navigationBar.tintColor = UIColor.blueColor()
self.navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blueColor()]

}

更多细节和信誉:Swift - iOS : Change the color of a Navigation Bar

希望这个帮助