Holy Swift

Holy Swift

How to do Gradient background colors in Swift ?

How to do Gradient background colors in Swift ?

Subscribe to my newsletter and never miss my upcoming articles

Hello folks Leo here,

Quick tip from what I learned today.

The code below make the background from white to yellowish. Obs: self here is the element that you want to have a gradient background

        let colorTop = UIColor.white.cgColor
        let colorBottom = UIColor(red: 0.941 , green: 0.818, blue: .zero, alpha: 1.0).cgColor

        let gradientLayer = CAGradientLayer()
        gradientLayer.frame = self.bounds
        gradientLayer.colors = [colorTop, colorBottom]
        self.layer.insertSublayer(gradientLayer, at: 0)

Thanks for reading!

#ios#color#swift#apple
 
Share this