如何使角和渐变颜色的按钮快速?

时间:2018-08-05 14:11:04

标签: ios swift

enter image description here

如何在Swift中制作带有角和渐变颜色的按钮。

1 个答案:

答案 0 :(得分:1)

尝试扩展-

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)
}
}