I want to set some shadow to the bottom of my UINavigationBar for the whole application. Here is what I've tried but it doesn't work:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UINavigationBar.appearance().layer.shadowOffset = CGSizeMake(0, 3)
UINavigationBar.appearance().layer.shadowRadius = 3.0
UINavigationBar.appearance().layer.shadowColor = UIColor.yellowColor().CGColor
UINavigationBar.appearance().layer.shadowOpacity = 0.7
}
Please, tell me how can I do this?
UPDATE: Solved by subclassing from UINavigationController
import UIKit
class ShadowUINavigationController: UINavigationController {
override func viewWillAppear(animated: Bool) {
let darkColor: CGColorRef = UIColor(hex: 0x212121).CGColor
let lightColor: CGColorRef = UIColor.clearColor().CGColor
let navigationBarBottom: CGFloat = self.navigationBar.frame.origin.y + self.navigationBar.frame.size.height + 20
println(self.navigationBar.frame.origin.y)
println(self.navigationBar.frame.size.height)
println(navigationBarBottom)
let newShadow: CAGradientLayer = CAGradientLayer()
newShadow.frame = CGRectMake(0, navigationBarBottom, self.view.frame.size.width, 1)
newShadow.colors = [darkColor, lightColor]
self.view.layer.addSublayer(newShadow)
super.viewWillAppear(animated)
}
}