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

Posted

技术标签:

【中文标题】转到下一个视图会更改导航栏背景颜色【英文标题】:Going to next view changes the navigation bar background color 【发布时间】:2017-11-22 07:38:17 【问题描述】:

当我使用 push 方法呈现新视图时,我的导航栏颜色的一小部分会在一段时间内发生变化,因为它在该部分显示为深蓝色,然后又恢复为浅色。

如图所示。

我应该如何解决这个问题

【问题讨论】:

【参考方案1】:

你可以在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

希望有帮助

【讨论】:

以上是关于转到下一个视图会更改导航栏背景颜色的主要内容,如果未能解决你的问题,请参考以下文章

刷新导航栏背景颜色

更改导航栏背景颜色后,self.view 的 y 位置发生更改

如何在所有场景中设置导航栏背景颜色

导航到下一个活动时更改操作栏颜色及其文本对齐方式

使导航栏活动链接背景颜色保持突出显示

swift xcode更改状态栏(背景颜色)