The best way to set gradient coloration in UIbutton?


How we are able to set gradient color in UIButton utilizing swift?

I’ve tried this:

func addGradient(btn : UIButton){
    let color1 = UIColor(purple: 221.0/255, inexperienced: 96.0/255, blue: 129.0/255, alpha: 1.0).cgColor
    let color2 = UIColor(purple: 171.0/255, inexperienced: 74.0/255, blue: 141.0/255, alpha: 1.0).cgColor
    let gradientLayer = CAGradientLayer()
    gradientLayer.colours = [color2,color1 ]
    gradientLayer.areas = [0.0, 1.0]
    gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.6)
    gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.6)
    btn.layer.insertSublayer(gradientLayer, at: 0)
}

it is not working correctly.

Similar Posts

Leave a Reply

Your email address will not be published.