I have this extension to add a Gradient to a View in Swift:
extension UIView {
func addGradientWithColor(colorTop: UIColor, colorButton: UIColor){
let gradient = CAGradientLayer()
gradient.frame = self.bounds
gradient.colors = [colorTop.cgColor, colorButton.cgColor]
self.layer.insertSublayer(gradient, at: 0)
}
}
Then, I use it like that in my UIViewController:
override func viewDidLoad(){
self.view.addGradientWithColor(colorTop: UIColor.red, colorButton: UIColor.clear)
super.viewDidLoad()
}
I run the simulator and it works great. But when I want use my app on a real device, the Gradient does not work.
PD: I tried many ways to do a Gradient but nothing worked on a real device.