有一个CAShapeLayer
当我将其添加为面具时,我得到一个空白的屏幕
这是我的代码:
let width: CGFloat = frame.width
let radius: CGFloat = (width - 35) / 2
let poing = CGPoint(x: width / 2, y: radius + 8)
let path = UIBezierPath(arcCenter: poing, radius: (width - 35) / 2,
startAngle: CGFloat(180).toRadians(),
endAngle: CGFloat(360).toRadians(),
clockwise: true)
let mask = CAShapeLayer()
mask.path = path.cgPath
mask.lineWidth = 8
mask.strokeStart = 0
mask.strokeEnd = 1
mask.lineCap = kCALineCapRound
mask.fillColor = UIColor.clear.cgColor
mask.strokeColor = progressColor.cgColor
let gradient = CAGradientLayer()
gradient.frame = CGRect(x: 0, y: 0, width: frame.width, height: frame.height)
gradient.startPoint = CGPoint(x: 0, y: 1)
gradient.endPoint = CGPoint(x: 1, y: 1)
gradient.colors = [UIColor.white, UIColor.blue]
gradient.mask = mask
layer.addSublayer(gradient)
我不明白为什么它不起作用。
答案 0 :(得分:1)
你忘记了CALayer总是使用CGColor。
gradient.colors = [UIColor.white.cgColor, UIColor.blue.cgColor]
希望有所帮助