How to remove border of the navigationBar in swift?

前端 未结 25 1739
执笔经年
执笔经年 2020-12-02 04:41

i\'ve been trying to remove the navigationBars border without luck. I\'ve researched and people seem to tell to set shadowImage and BackgroundImage to nil, but this does not

相关标签:
25条回答
  • 2020-12-02 05:13
    let navBarAppearance = UINavigationBarAppearance()
    navBarAppearance.configureWithTransparentBackground()
    
    0 讨论(0)
  • 2020-12-02 05:13

    This is a streamlined version of Gaurav Chandarana's answer.

    extension UINavigationBar {
    
        func hideShadow(_ value: Bool = true) {
            setValue(value, forKey: "hidesShadow")
        }
    }
    
    0 讨论(0)
  • 2020-12-02 05:13

    App delegate

    UINavigationBar.appearance().setBackgroundImage(UIImage(), for: UIBarMetrics.default)
    UINavigationBar.appearance().shadowImage = UIImage()
    
    0 讨论(0)
  • 2020-12-02 05:15

    Swift 4 & Swift 5

    Removing border:

    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for:.default)
    self.navigationController?.navigationBar.shadowImage = UIImage()
    self.navigationController?.navigationBar.layoutIfNeeded()
    

    Restoring border:

    self.navigationController?.navigationBar.setBackgroundImage(nil, for:.default)
    self.navigationController?.navigationBar.shadowImage = nil
    self.navigationController?.navigationBar.layoutIfNeeded()
    
    0 讨论(0)
  • 2020-12-02 05:15

    With Swift 2 you can do it this way:

    AppDelegate file

    Inside func application(..., didFinishLaunchingWithOptions launchOptions:...)

    UINavigationBar.appearance().shadowImage = UIImage()
    UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)
    

    for Swift 3:

    UINavigationBar.appearance().shadowImage = UIImage()
    UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
    
    0 讨论(0)
  • 2020-12-02 05:15

    Within AppDelegate, this has globally changed the format of the NavBar and removes the bottom line/border:

     func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
        UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarPosition: UIBarPosition.Any, barMetrics: UIBarMetrics.Default)
        UINavigationBar.appearance().shadowImage = UIImage()
        UINavigationBar.appearance().tintColor = UIColor.whiteColor()
        UINavigationBar.appearance().barTintColor = UIColor.redColor()
        UINavigationBar.appearance().translucent = false
        UINavigationBar.appearance().clipsToBounds = false
        //UINavigationBar.appearance().backgroundColor = UIColor.redColor()
        UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName : (UIFont(name: "FONT NAME", size: 18))!, NSForegroundColorAttributeName: UIColor.whiteColor()] }
    

    Haven't managed to implement anything different on a specific VC, but this will help 90% of people

    0 讨论(0)
提交回复
热议问题