删除导航栏下面的阴影线,而不删除栏颜色?
我已经尝试了许多类似问题的答案,但是他们都没有为我工作。 我试图删除导航栏1px的阴影,但我试过的一切结束删除栏的颜色,并使其白色/浅色。 任何想法如何删除它(在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 }
以上是我的代码,这是我所尝试过的:
UINavigationBar.appearance().shadowImage = UIImage() UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)
但是每一次,不pipe它在哪条线上,酒吧开始看起来像这样,而不是我已经设定的蓝色。
你用来去除阴影的线条很好
UINavigationBar.appearance().shadowImage = UIImage() UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)
但你也需要确保,导航栏不是半透明的(这是默认情况下),以显示您的实心barTintColor
UINavigationBar.appearance().isTranslucent = false
在你的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
放置这个:
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
迅速:
放在代码下面
UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarPosition: .Any, barMetrics: .Default) UINavigationBar.appearance().shadowImage = UIImage()
里面的方法如下
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
来源: https : //stackoverflow.com/a/35151251/1585677