navigationController?.navigationBar.layer.shadowColor = ColorPalette.navigationBarShadowColor.cgColor
set color according to mode.
class ColorPalette : NSObject {
static var navigationBarShadowColor: UIColor {
return UIColor { (traits) -> UIColor in
//dark: Black // light: grey16
return traits.userInterfaceStyle == .dark ?
UIColor.black : UIColor(hex: "dbdbdc")
}
}
}
CodePudding user response:
Add this in AppDelegate
UINavigationBar.appearance().shadowColor = UITraitCollection.current.userInterfaceStyle == .light ? UIColor(named: "light_color") : UIColor(named: "dark_color")
CodePudding user response:
remove navigationBar shadow
self.navigationController?.navigationBar.shadowImage = UIImage()
if iOS 13
self.navigationController?.navigationBar.standardAppearance.shadowColor = UIColor.black
CodePudding user response:
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
self.navigationController?.navigationBar.standardAppearance.shadowColor = UIColor.black.cgColor
}
we are using this and it is working but we want only one class we have to add this type of code like AppDelegate or some other classes .