【问题标题】:UINavigationBarAppearance not working for image based bar button itemsUINavigationBarAppearance 不适用于基于图像的栏按钮项目
【发布时间】:2019-08-24 03:08:05
【问题描述】:

Xcode 版本 11.0 beta 5 (11M382q)

当我的视图控制器之一是顶视图控制器时,我正在使用新的外观 API 为条形按钮项的颜色着色。我正在使用以下代码:

let appearance = UINavigationBarAppearance()
let attributes: [NSAttributedString.Key : Any] = [.foregroundColor : tintColor]

appearance.largeTitleTextAttributes = attributes
appearance.buttonAppearance.normal.titleTextAttributes = attributes
appearance.doneButtonAppearance.normal.titleTextAttributes = attributes

navigationItem.standardAppearance = appearance

这似乎适用于基于文本的栏按钮项目,但基于图像的栏按钮项目保持应用程序的默认色调。这是 iOS 13 测试版中的错误吗?我已经记录了一个雷达,但只是想看看其他人是否遇到过这个问题或找到了解决方法。

如下所示,后退箭头和加号按钮的颜色不正确。

【问题讨论】:

  • 这个运气好吗?也有这个问题,不知道从哪里开始。
  • 很遗憾,我还没弄清楚是什么原因造成的。
  • 对此的任何进一步更新。还是我们仍在等待 Apple 提供此功能?
  • 我还没有找到解决方法。

标签: ios swift ios13


【解决方案1】:

你必须设置:

let backImage = appearance.backIndicatorImage.tint(with: tintColor)
appearance.setBackIndicatorImage(backImage, transitionMaskImage: backImage)

【讨论】:

  • 这不适用于其他基于图像的条形按钮项目,但它可能适用于背面图像。
  • 对于其他图像,您仍然可以像以前版本的 iOS 一样使用“self.navigationController?.navigationBar.tintColor = tintColor”。目前我认为 UIBarButtonItemAppearance 只允许设置文本颜色
【解决方案2】:

这只是没有设置以下的情况:

UINavigationBar.appearance().barTintColor = UIColor.black
UINavigationBar.appearance().tintColor = UIColor.white

我没有设置这些,因为我认为新的 UINavigationBarAppearance() 替换了它们,但设置这些可以解决问题。我认为这将在 GM 或未来版本中更新,尽管混合使用新旧 API 似乎很奇怪。

【讨论】:

  • 不幸的是,这对我的需要不起作用。我正在尝试将导航控制器中的这个顶视图控制器的色调设置为黄色。导航控制器中其余视图控制器的色调应为红色。
【解决方案3】:

经过多次尝试和错误,我终于得到了这个工作:

UIImage *image = [[[UIImage systemImageNamed:@"chevron.left" withConfiguration:[UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightSemibold]] imageWithTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.navigationController.navigationBar.backIndicatorImage = image;
self.navigationController.navigationBar.backIndicatorTransitionMaskImage = image;

但这当然不适用于 iOS 15。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-16
    • 2017-03-13
    • 2012-01-14
    • 2013-12-06
    • 2020-08-31
    • 1970-01-01
    • 2021-04-13
    • 2016-10-04
    相关资源
    最近更新 更多