Mike Schmidt Mike Schmidt - 1 year ago 100
Swift Question

Remove Shadow Line Below Navigation Bar Without Removing Bar Color?

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();


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...

Answer Source

in your

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

place this:

  [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init]

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


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: http://stackoverflow.com/a/35151251/1585677

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download