【问题标题】:Tintcolor left back arrow navigationBar changes after closing UIAlertController (IOS)关闭 UIAlertController (IOS) 后 Tintcolor 左后箭头导航栏发生变化
【发布时间】:2016-09-13 10:57:59
【问题描述】:

编辑:自定义代码 此问题是由于在应用程序初始加载期间设置所有对象的 tintColor 造成的。


我的代码中有一个非常奇怪的情况。左后退箭头的 tintColor 正在更改为另一种颜色:

  1. 呈现 UIAlertController
  2. 关闭 UIAlertController
  3. 切换标签。 (标签切换时可以看到颜色的变化)。

更改颜色后,我无法将其设置回原来的颜色。

我尝试了什么?

1) 在多个位置重新设置颜色。 (ViewWillAppear / ViewDidAppear)。

self.navigationItem.backBarButtonItem?.tintColor = UIColor.redColor()
self.navigationController?.navigationBar.tintColor  = UIColor.redColor()

2) 设置外观。

UINavigationBar.appearance().tintColor = UIColor.yellowColor()

3) 试图覆盖方法 didSetTintColor

4) 发布 UIAlertView 后更改 tintColor(示例如下)

UIAlertAction(title: "Example button", style: .Cancel, handler: { action in
        alertController.removeFromParentViewController()
        self.navigationItem.backBarButtonItem?.tintColor = UIColor.greenColor()
        self.navigationController?.navigationBar.tintColor  = UIColor.greenColor() 
})

5) 试过这个解决方案: Navigation bar tint color changes after auto dimissal of UIAlertView

似乎没有任何效果。这可能是一个IOS错误吗? 奇怪的是切换标签后不会发生变化,但不使用UIAlertViewController时也不会发生变化。

【问题讨论】:

  • 后退图标颜色是什么?黄色?
  • 正常颜色是 UIColor.whiteColor()。 (我尝试设置不同的颜色,以在代码中找到正确的位置)。颜色变为蓝色。 (这是应用程序的默认 Tintcolor)
  • 显示切换标签代码
  • 我编辑了帖子!

标签: ios swift navigationbar tintcolor


【解决方案1】:

尝试设置TintAdjustmentMode

 [self.view setTintAdjustmentMode:UIViewTintAdjustmentModeNormal];

 [self.view setTintAdjustmentMode:UIViewTintAdjustmentModeAutomatic];

【讨论】:

  • 嗨 Lion,我试过这个(也在 AlmanappDelegate.swift 中。)没有任何变化。当我将此设置为 .Normal 时,从一开始就会显示错误的颜色。
【解决方案2】:

我发现了问题。在应用程序委托中,一个函数正在设置整个应用程序的所有 tintColors。显然 ActionController 的关闭会再次改变 tintColors

 for window in UIApplication.sharedApplication().windows {
        window.tintColor = UIColor.wrongColor()
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-14
    • 2021-11-15
    相关资源
    最近更新 更多