繁体   English   中英

SwiftUI 移除 NavigationBar 底部边框

[英]SwiftUI Remove NavigationBar Bottom Border

使用 SwiftUI 时如何删除导航栏的底部 1px 边框?

iOS SwiftUI NavigationBar 示例

在 View 的初始化程序中,您可以设置导航栏的外观。 在那里,您必须将.shadowColor属性设置为.clear

init() {
    let appearance = UINavigationBarAppearance()
    appearance.shadowColor = .clear
    UINavigationBar.appearance().standardAppearance = appearance
    UINavigationBar.appearance().scrollEdgeAppearance = appearance
}

我也遇到过这个问题。 这是几乎相似的帖子

但大多数答案都有副作用。 对我来说,最好的解决方案是这个

UINavigationBar.appearance().barTintColor = .clear
UINavigationBar.appearance().backgroundColor = .clear 
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
UINavigationBar.appearance().shadowImage = UIImage()

并且还希望将 UIImage() 而不是“nil”设置为 shadowImage 和 bacgroundImage。 我做了导航 displayMode 内联

.navigationBarTitle(Text(""), displayMode: .inline)

在 Xcode 12.4 中,这是对我有用的组合:

init() {
    UINavigationBar.appearance().shadowImage = UIImage()
    UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
    UINavigationBar.appearance().isTranslucent = false
    UINavigationBar.appearance().barTintColor = UIColor.red
}

SwiftUI,1 线。

UINavigationBar.appearance().standardAppearance.shadowColor = .clear

我实现了 inside.onAppear {}

这对我有用

UINavigationBar.appearance().shadowImage = UIImage()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM