You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS15下UIKit项目修改导航栏及返回按钮颜色失效如何解决

问题点

  • iOS15分支中你给临时创建的UINavigationBar实例设置tintColor,该配置不会作用到全局导航栏,返回按钮颜色由UINavigationBar.appearance().tintColor控制
  • 未配置UINavigationBarAppearance的返回按钮属性,iOS15后返回按钮样式可通过该配置统一生效

修复代码

if #available(iOS 15.0, *) {
    let appearance = UINavigationBarAppearance()
    appearance.configureWithOpaqueBackground()
    appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
    appearance.backgroundColor = .red
    // 配置返回按钮文字颜色
    appearance.backButtonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.white]
    // 全局外观配置
    let globalNavBarAppearance = UINavigationBar.appearance()
    globalNavBarAppearance.tintColor = .white
    globalNavBarAppearance.standardAppearance = appearance
    globalNavBarAppearance.scrollEdgeAppearance = appearance
} else {
    let navBarAppearance = UINavigationBar.appearance()
    navBarAppearance.tintColor = .white
    navBarAppearance.barTintColor = .red
    navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
}

最终效果

导航栏效果

内容的提问来源于stack exchange,提问作者Dilan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 18:45:03