Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift UINavigation Bottom Line and Shadow Remove without Navbar Color Change

Tags:

ios

swift

My Scenario, I am trying to remove bottom line and shadow from UINavigationBar using iOS 13 - Swift 5. Here, Before iOS 13 - Swift 5, I used below code for removing bottom line and shadow without changing navigation bar color. Now, It is not showing NavigationBar color (I already set Bar Color and Background Color) also disabled Transulent.

Code:

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

How to fix this? Need to remove bottom line shadow and also want to give NavigationBar Colour.

like image 424
Jam Ku Avatar asked Jul 09 '19 13:07

Jam Ku


2 Answers

For me, it only worked after changing the following (>= iOS13)

let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
navBarAppearance.shadowColor = .clear
navBarAppearance.shadowImage = UIImage()
navigationController?.navigationBar.standardAppearance = navBarAppearance
navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
like image 185
johannes Avatar answered Sep 28 '22 02:09

johannes


XCODE 13 - iOS 15

For Xcode 13 and targeting iOS ver 13 and above you can use this code:

 if #available(iOS 13.0, *) {
                let appearance = UINavigationBarAppearance()
                appearance.configureWithOpaqueBackground()
                appearance.backgroundColor = .red // Your color
                appearance.shadowColor = .clear
                appearance.shadowImage = UIImage()
                navigationController?.navigationBar.standardAppearance = appearance;
                navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance

            }
like image 23
Sajjad Sarkoobi Avatar answered Sep 28 '22 03:09

Sajjad Sarkoobi