我尝试创建一个包含 10 个按钮的 View 来创建 1 个运行超过 10 个 View 按钮的渐变动画,但不能。只为按钮制作渐变。大家有什么办法吗?
这是我的代码。我尝试过,但我希望它对标题按钮的整个颜色进行渐变
let insets: UIEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
let gradient = CAGradientLayer()
gradient.frame = self.view.bounds//path.bounds
gradient.colors = [UIColor.magenta.cgColor, UIColor.cyan.cgColor]
let shapeMask = CAShapeLayer()
let path = UIBezierPath(rect: button1.frame)
path.append(UIBezierPath(rect: button2.frame))
path.append(UIBezierPath(rect: button3.frame))
shapeMask.path = path.cgPath
gradient.mask = shapeMask
let whiteMask = CAShapeLayer()
whiteMask.fillColor = UIColor.white.cgColor
let whitePath = UIBezierPath(rect: button1.frame.inset(by: insets))
whitePath.append(UIBezierPath(rect: button2.frame.inset(by: insets)))
whitePath.append(UIBezierPath(rect: button3.frame.inset(by: insets)))
whiteMask.path = whitePath.cgPath
self.bgView.layer.addSublayer(gradient)
self.bgView.layer.addSublayer(whiteMask)
最佳答案
关于ios - 如何在 10 个按钮中快速创建 1 个带颜色的微光渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56163623/