Basim Hammad
Basim Hammad

Reputation: 1

how can make button with Corner and gradient color in swift?

enter image description here

how can i make button with corners and gradient color in Swift.

Upvotes: 0

Views: 54

Answers (1)

shivi_shub
shivi_shub

Reputation: 1058

Try the extension-

extension UIButton
{
func applyGradient(colors: [CGColor])
{
    let gradientLayer = CAGradientLayer()
    gradientLayer.colors = colors
    gradientLayer.startPoint = CGPoint(x: 0, y: 0)
    gradientLayer.endPoint = CGPoint(x: 1, y: 0)
    gradientLayer.frame = self.bounds
    self.layer.addSublayer(gradientLayer)
}
}

Upvotes: 1

Related Questions