let layer = CAGradientLayer()
layer.frame = CGRect(x: 0, y: 0, width: (ScreenWidth - 24.S)/2, height: 36.S)//按钮所在区域
layer.startPoint = CGPoint(x: 0, y: 0)
layer.endPoint = CGPoint(x: 1, y: 1)
let starColor = rgba(183, 138, 94, 1)
let endColor = rgba(230, 177, 94, 1)
layer.colors = [starColor.cgColor, endColor.cgColor]
layer.locations = [0, 1]
btn.layer.addSublayer(layer)将自定义的layer添加在btn的layer上面
显示效果图一
图一
网友评论