I am trying to apply the gradient color to UINavigationBar.appearence()
. For this ,I followed the link. But after adding that extension of CAGradientLayer
class,I have written the below lines of code in did finish launching with options in APPDelegate
class. But I am getting an error like "Value of optional type UIImage?
must be unwrapped to a value of type UIImage
".Here am using UINavigationbar
. Not the Navigationcontroller
Can anyone help me to do this, would be great.
// In AppDelegate Class
let navigationbar=UINavigationBar()
let flareGradientImage = CAGradientLayer.primaryGradient(on: navigationbar)
UINavigationBar.appearance().tintColor = UIColor(patternImage: flareGradientImage)
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]