Andriy Gordiychuk
Andriy Gordiychuk

Reputation: 6272

Make UINavigationBar white and without border

I am trying to remove a border from UINavigationBar while making it completely white so that it blends with the background.

Here is the code which I have:

nav.navigationBar.standardAppearance.shadowColor = UIColor.white //also tried UIColor.clear
nav.navigationBar.barTintColor = UIColor.white
nav.navigationBar.backgroundColor = UIColor.white
nav.navigationBar.barStyle = .default
nav.navigationBar.isTranslucent = false

The end result is depicted in the image below. As you can see, my navigation bar is not completely white:

enter image description here

If I remove the line where I set shadowColor I do get a white background, but with a line at the bottom.

I would appreciate if someone could help me to get the result which I want.

Upvotes: 0

Views: 43

Answers (1)

Frankenstein
Frankenstein

Reputation: 16341

Check out this code:

let appearance                      = UINavigationBarAppearance()
appearance.backgroundColor          = .white
appearance.shadowColor              = .none
appearance.titleTextAttributes      = [.foregroundColor: UIColor.white]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]

UINavigationBar.appearance().tintColor            = .black
UINavigationBar.appearance().standardAppearance   = appearance
UINavigationBar.appearance().compactAppearance    = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance

Upvotes: 1

Related Questions