x-code swift button a gradient verme

class ViewController: UIViewController {
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()

let background = CAGradientLayer().backgroundGradientColor()
background.frame = self.button.bounds
self.button.layer.insertSublayer(background, at: 0)
}
}

extension CAGradientLayer {
func backgroundGradientColor() -> CAGradientLayer {
let topColor = UIColor(red:0.04, green:0.33, blue:0.73, alpha:1.0)
let bottomColor = UIColor(red:0.03, green:0.24, blue:0.53, alpha:1.0)
let gradientColors: [CGColor] = [topColor.cgColor, bottomColor.cgColor]
let gradientLocations: [Float] = [0.0, 1.0]
let gradientLayer: CAGradientLayer = CAGradientLayer()
gradientLayer.cornerRadius = 20
gradientLayer.colors = gradientColors
gradientLayer.locations = gradientLocations as [NSNumber]
gradientLayer.startPoint = CGPoint(x: 0.0,y :0.5)
gradientLayer.endPoint = CGPoint(x: 1.0,y :0.5)
return gradientLayer
}
}

You may also like...

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir