Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Remove NavigationBar Bottom Border

Tags:

ios

swift

swiftui

When using SwiftUI how do you remove the bottom 1px border of a navigation bar?

iOS SwiftUI NavigationBar Example

like image 263
outerstorm Avatar asked Oct 18 '19 00:10

outerstorm


2 Answers

In the initializer of your View you can set the appearance of your navigation bar. There you have to set the .shadowColor property to .clear.

init() {
    let appearance = UINavigationBarAppearance()
    appearance.shadowColor = .clear
    UINavigationBar.appearance().standardAppearance = appearance
    UINavigationBar.appearance().scrollEdgeAppearance = appearance
}
like image 98
Niels Hoogendoorn Avatar answered Oct 20 '22 15:10

Niels Hoogendoorn


I have also met this problem. Here is the almost similar post

But most of the answer had side effect. And for me, the best solution was this

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

and also want its important to set UIImage() not 'nil' to shadowImage and bacgroundImage. And I made navigation displayMode inline

.navigationBarTitle(Text(""), displayMode: .inline)
like image 23
Islom Alimov Avatar answered Oct 20 '22 16:10

Islom Alimov