我最近开始使用SwiftUI,得出结论:与导航一起工作还不够好。我想要实现的是以下内容。我终于设法在不使应用程序崩溃的情况下摆脱了半透明背景,但现在我遇到了下一个问题。如何去除navbaritem内部的“返回”文本?
我通过在SceneDelegate.swift
文件中设置默认外观来实现上述视图,如下所示。
let newNavAppearance = UINavigationBarAppearance()
newNavAppearance.configureWithTransparentBackground()
newNavAppearance.setBackIndicatorImage(UIImage(named: "backButton"), transitionMaskImage: UIImage(named: "backButton"))
newNavAppearance.titleTextAttributes = [
.font: UIFont(name: GTWalsheim.bold.name, size: 18)!,
.backgroundColor: UIColor.white
]
UINavigationBar.appearance().standardAppearance = newNavAppearance
我能够通过覆盖导航栏项来实现这一目标,但这种方法有一个缺点(SwiftUI定制NavigationView的返回按钮文本),正如此问题的创建者所说,覆盖导航栏项后,返回手势将停止工作。同时,我也想知道如何设置返回按钮的foregroundColor。它现在具有默认的蓝色,但我想用另一种颜色来覆盖它。
super.viewWillLayoutSubviews()
。 - D. Greg