【发布时间】:2020-05-30 14:54:49
【问题描述】:
我有一个带有大标题和内容的 NavigationBar 视图。我更改了内容背景颜色和 NavigationBar 背景颜色。
var body: some View {
NavigationView {
VStack {
//content
}.background(Color.green)
.edgesIgnoringSafeArea(.bottom) //to fill the white space at the bottom
.navigationBarTitle("Wallets")
}
}
extension UINavigationController {
override open func viewDidLoad() {
super.viewDidLoad()
let standartAppearance = UINavigationBarAppearance()
standartAppearance.backgroundColor = UIColor.green
navigationBar.standardAppearance = standartAppearance
navigationBar.scrollEdgeAppearance = standartAppearance
navigationBar.compactAppearance = standartAppearance
}
}
现在,如果我使用 NavigationLink 移动到下一个视图,并且该视图的标题为 .inline 显示模式(不同的 NavigationBar 大小),则在转换时我会看到第一个导航栏下方的空白。如果我为我的 VStack 制作 .edgesIgnoringSafeArea(.all),我可以填充它,但在这种情况下,我的所有内容都会跳到 NavigationBar 下。如何将 NavigationBar 下的空间着色为自定义颜色?
【问题讨论】:
-
你修复成功了吗?
-
我没有找到正常的解决方案,请参阅下面的解决方法。
-
是的,太好了。我正在用偏移量修复它!
标签: swift swiftui background-color navigationbar