How to add a line below Navigation bar in the pushed View Controller?

SriTeja Chilakamarri

I have a UINavigation Controller which is used to push or pop Views. In the Initial view controller I want to hide the navigation Bar bottom 1 Pixel shadow. So I here's the code for that.

func setup(){

        if #available(iOS 11.0, *) {
            self.navigationController?.navigationBar.prefersLargeTitles = true
            self.navigationController?.navigationItem.largeTitleDisplayMode = .always
        } else {
            // Fallback on earlier versions
        }

        self.navigationBar.isTranslucent = true


        self.navigationBar.clipsToBounds = true
        self.navigationBar.setBackgroundImage(UIImage(), for: .default)
        self.navigationBar.shadowImage = UIImage()

        self.navigationBar.tintColor = UIColor(hexString: "#373839")
        self.navigationBar.backgroundColor = UIColor.white

    }

But when I push to second View controller the Navigation Bar's shadow is hidden even in this.

Does setting the Navigation Bar's properties in the Parent view controller effect those in all the controllers pushed from there on ? I thought Navigation Bar is specific to View controller a Navigation controller creates a new Navigation Bar for each pushed view.

Could someone help me understand this and how I could have 1 pixel shadow back on the Navigation Bar for only 1 view.

McDonal_11

Add below code in ViewController where you want to change color of NavigationBar's Shadow .

func addColorToShadow() {

     self.navigationController?.navigationBar.clipsToBounds = false
     self.navigationController?.navigationBar.shadowImage = UIColor(red: 215/255, green: 215/255, blue: 215/255, alpha: 1.0).image(CGSize(width: self.view.frame.width, height: 1))

}


extension UIColor {
    func image(_ size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
        return UIGraphicsImageRenderer(size: size).image { rendererContext in
            self.setFill()
            rendererContext.fill(CGRect(x: 0, y: 0, width: size.width, height: size.height))
        }
    }
}

Output

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Add a navigation bar to a view without a navigation controller

How to check if navigation controller is pushed or is a root view controller?

How to make navigation bar's sub view pushed with view

Add navigation bar to a view controller without a navigation controller

How to check if a view controller is presented modally or pushed on a navigation stack?

Navigation Bar Navigation Items causing top area of buttons on pushed view controller to not be tappable

Add accessory view below navigation bar title in SwiftUI

Swift-How do I add Tab Bar AND Navigation Bar to a single view controller?

How to get the navigation bar on view controller?

How to make the transition to a view controller with a navigation bar?

how to add a navigation controller to a view that is not the main view?

Dismiss pushed view from within Navigation Controller

Add a line below each item selected in bottom navigation view

How can I Adjust view height to be below navigation bar in iOS?

How to go "without navigation bar view controller" to "with navigation bar view controller" in Swift

How do you add a bar button item to all View Controllers in a Navigation Controller

How to add a line to the bottom Navigation Bar

How to add custom view on Navigation bar

Navigation Controller : What is below the topmost view controller in navigation controller on the window?

Hide Navigation Bar for a View Controller

view controller's navigation controller property is nil after being pushed

How to add a navigation controller programmatically in code but not as initial view controller

how to change navigation bar color for the current view controller only

How to hide a navigation bar from one particular view controller

How to segue with a UITableViewController without navigation bar showing on other view controller?

How to go to other view Controller using Navigation Bar Item?

Bottom Navigation Bar being pushed out of view by a Scrollview Layout

Navigate from a navigation bar view controller to a tab bar view controller

How to add a custom tab bar to a project oriented by navigation controller