删除导航栏下面的阴影线而不删除栏颜色?

时间:2016-08-05 19:08:59

标签: ios swift xcode

我尝试过类似问题中的许多答案,但没有一个对我有用。我试图删除导航栏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)

但每次,无论它在哪一条线上,条形开始看起来像这样而不是我设定的蓝色......

2 个答案:

答案 0 :(得分:4)

用于移除阴影的线条很好

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

但您还需要确保导航栏不是半透明的(默认情况下是这样),以显示您的实心条纹色彩

UINavigationBar.appearance().isTranslucent = false

答案 1 :(得分:3)

中的

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