我正在使用Swift进行开发,并希望制作一个带有渐变图层的圆角按钮。在按钮的角落,渐变图层显示在按钮外部。怎么解决?
这是我为它制作的代码:
let newLayer = CAGradientLayer()
newLayer.frame = button.bounds
newLayer.colors = [UIColor.white.cgColor, UIColor.lightGray.cgColor]
button.layer.insertSublayer(newLayer, at: 0)
button.layer.cornerRadius = 10.0
button.layer.borderWidth = 3.0
button.layer.borderColor = UIColor.darkGray.cgColor
button.layer.shadowColor = UIColor.black.cgColor
button.layer.shadowOpacity = 1.0
button.layer.shadowRadius = 5.0
button.layer.shadowOffset = CGSize.init(width: 3, height: 3)