I know how to set a navigation bar background color (with barTintColor), but now I am working on an iOS app that calls for a horizontal gradient (not the typical vertical gradie
Swift
Add this function in global class
func setHorizontalGradientColor(view: UIView) {
let gradientLayer = CAGradientLayer()
var updatedFrame = view.bounds
updatedFrame.size.height += 20
gradientLayer.frame = updatedFrame
gradientLayer.colors = [UIColor.black.cgColor, UIColor.blue.cgColor]
gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5)
gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.5)
view.layer.insertSublayer(gradientLayer, at: 0)
}
Use in anywhere:
setHorizontalGradientColor(view: self.bgView)