ios - 如何在 10 个按钮中快速创建 1 个带颜色的微光渐变

标签 ios swift

我尝试创建一个包含 10 个按钮的 View 来创建 1 个运行超过 10 个 View 按钮的渐变动画,但不能。只为按钮制作渐变。大家有什么办法吗?

enter image description here

这是我的代码。我尝试过,但我希望它对标题按钮的整个颜色进行渐变

 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)

最佳答案

希望这足以表明需要什么......

Gradient example

关于ios - 如何在 10 个按钮中快速创建 1 个带颜色的微光渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56163623/

相关文章:

javascript - iOS 上的 WebViewJavascriptBridge

ios - FBSDKCoreKit.framework/FBSDKCoreKit : no matching architecture in universal wrapper

ios - Swift 以编程方式删除标签栏

ios - 使用 UIView 动画时的 UIButton.frame

ios - 如何在 UipageViewController swift 中预加载下一个和上一个 View

swift - 当我尝试将 "Font"应用于一个 tableview 单元格时,它会在滚动 tableview 时自动应用于其他单元格

arrays - 快速将数组序列化为对象

ios - 如何通过 AVCaptureVideoDataOutput() 和 AVCaptureSession() 快速录制视频

ios - 如何使 ImageView 像 facebook iOS 应用程序一样旋转?

iphone - 在iOS中使用控件播放音频