let stressLayer:CAShapeLayer = CAShapeLayer()
stressLayer.frame = .init(x: 0, y: Avglabel.frame.maxY, width: SCREEN_WIDTH, height: 40)
let gradientLater:CAGradientLayer = CAGradientLayer()
gradientLater.frame = stressLayer.bounds
gradientLater.colors = [stress_greenColor.cgColor,
stress_greenColor.cgColor,
stress_blueColor.cgColor,
stress_blueColor.cgColor,
stress_orangeColor.cgColor,
stress_orangeColor.cgColor,
stress_redColor.cgColor]
gradientLater.locations = [0,
0.25,
0.25,
0.5,
0.5,
0.75,
0.75,
1.0];
gradientLater.startPoint = CGPoint.init(x: 0, y: 0.5)
gradientLater.endPoint = CGPoint.init(x: 1, y: 0.5)
stressLayer.addSublayer(gradientLater)
本文介绍如何使用SwiftUI及Core Animation创建一个带有颜色渐变效果的图层。该图层从绿色过渡到蓝色,再到橙色和红色,并沿水平方向进行渐变,通过调整颜色和位置参数可以实现丰富的视觉效果。
1323

被折叠的 条评论
为什么被折叠?



