随着 ios 12 和 swift 4.2 的到来,我的代码不再工作了。它曾经是从左到右,深紫色到浅紫色的渐变按钮。我怎样才能解决这个问题?
// Gives the button gradient values
func setGradientButton(colorOne: UIColor, colorTwo: UIColor, x1: Double, y1: Double, x2: Double, y2: Double) {
let gradientLayer = CAGradientLayer()
gradientLayer.frame = bounds
gradientLayer.colors = [colorOne.cgColor, colorTwo.cgColor]
gradientLayer.locations = [0.0, 0.0]
gradientLayer.startPoint = CGPoint(x: x1, y: y1)
gradientLayer.endPoint = CGPoint(x: x2, y: y2)
layer.insertSublayer(gradientLayer, at: 0)
}
// Sets UI elements
func setUI(_ label : UILabel, _ button : UIButton) {
let colorOne = UIColor(red: 119.0 / 255.0, green: 85.0 / 255.0, blue: 254.0 / 255.0, alpha: 100.0)
let colorTwo = UIColor(red: 177.0 / 255.0, green: 166.0 / 255.0, blue: 251.0 / 255.0, alpha: 100.0)
button.setGradientButton(colorOne: colorOne, colorTwo: colorTwo, x1: 0.0, y1: 50, x2: 150, y2: 50)
button.layer.cornerRadius = 4
button.clipsToBounds = true
}