I use the code below for gradient color. But when I use that code it colors the whole view controller. It also covers the other contents too like textfield, label, etc. I want to use multiple views with multiple gradient colors in a view controller. Suppose I have three views in a view controller and I want to use three different gradient colors in three different views. Content like label and textfield will appear on the gradient colors.
Here is my code:
func setBackground_view() {
let gradientLayer = CAGradientLayer()
let colorTop = UIColor(red: 44/255.0, green: 156/255.0, blue: 56/255.0, alpha: 1.0).cgColor
let colorBottom = UIColor(red: 155/255.0, green: 180/255.0, blue: 23/255.0, alpha: 1.0).cgColor
gradientLayer.colors = [ colorTop, colorBottom]
gradientLayer.startPoint = CGPoint(x: 1.0, y: 0.5)
gradientLayer.endPoint = CGPoint(x: 0.0, y: 1.0)
gradientLayer.frame = self.view.bounds
self.view.layer.addSublayer(gradientLayer)
self.view.layer.insertSublayer(gradientLayer, at: 0)
view.layer.addSublayer(gradientLayer)
}