2

I have tried many of the answers shown in similar questions, but none of them have worked for me. I am trying to remove the navigation bar 1px shadow, but everything I tried ends up removing the bar color and making it white/some light color. Any idea how to remove it (inside App Delegate?)

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {


    let redPart: CGFloat = CGFloat(65) / 255
    let greenPart: CGFloat = CGFloat(107) / 255
    let bluePart: CGFloat = CGFloat(166) / 255
    UINavigationBar.appearance().shadowImage = UIImage()
    UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)

    UINavigationBar.appearance().barTintColor = UIColor(red: redPart, green: greenPart, blue: bluePart, alpha: 1.0)
    //Set the colors for bar button items and text
    UINavigationBar.appearance().tintColor = UIColor.whiteColor()
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor(), NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 22)!]



    // Override point for customization after application launch.
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.checkForReachability(_:)), name: kReachabilityChangedNotification, object: nil);

    self.reachability = Reachability.reachabilityForInternetConnection();

    self.reachability!.startNotifier()


    return true
}

Above is my code, and this is what I have tried:

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

But every time, no matter what line it is on, the bar starts to look like this instead of the blue color I had set it to...

Mike Schmidt
  • 945
  • 3
  • 12
  • 31
  • Possible duplication: http://stackoverflow.com/questions/32208378/how-to-remove-the-shadow-line-from-a-navigation-bar?rq=1 However it's possible, check how Chameleon did this: https://github.com/ViccAlexander/Chameleon/blob/master/Pod/Classes/Objective-C/UINavigationController%2BChameleon.m or https://github.com/samwize/UINavigationBar-Addition/ – Grubas Aug 05 '16 at 19:30
  • Possible duplicate of [How to hide iOS7 UINavigationBar 1px bottom line](http://stackoverflow.com/questions/19226965/how-to-hide-ios7-uinavigationbar-1px-bottom-line) – jjatie Feb 08 '17 at 14:35

2 Answers2

4

the lines you used to remove the shadow are fine

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

but you also need to make sure, the navigation bar isn't translucent (which it is by default), to show your solid barTintColor

UINavigationBar.appearance().isTranslucent = false

dalipsia
  • 186
  • 1
  • 7
3

in your

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

place this:

  [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init]
                                  forBarPosition:UIBarPositionAny
                                      barMetrics:UIBarMetricsDefault];

[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];

Swift:

place below code

UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarPosition: .Any, barMetrics: .Default)
UINavigationBar.appearance().shadowImage = UIImage()

inside method below

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool

source: https://stackoverflow.com/a/35151251/1585677

Community
  • 1
  • 1
Eugene Gordin
  • 4,047
  • 3
  • 47
  • 80