【发布时间】:2018-07-07 19:40:32
【问题描述】:
我想使用带有渐变颜色的UIBazierpath 填充圆形边框的一半。
最初我尝试使用完整的圆圈,但它不起作用,渐变总是填充圆圈而不是边框。有没有办法做到这一点?
这是我目前所拥有的:
let path = UIBezierPath(roundedRect: rect, cornerRadius: rect.width/2)
let shape = CAShapeLayer()
shape.path = path.cgPath
shape.lineWidth = 2.0
shape.strokeColor = UIColor.black.cgColor
self.layer.addSublayer(shape)
let gradient = CAGradientLayer()
gradient.frame = path.bounds
gradient.colors = [UIColor.magenta.cgColor, UIColor.cyan.cgColor]
let shapeMask = CAShapeLayer()
shapeMask.path = path.cgPath
gradient.mask = shapeMask
shapeMask.lineWidth = 2
self.layer.addSublayer(gradient)
【问题讨论】:
-
什么是“darwan”?目前还不清楚你的目标是什么。你有你想要的结果的图片吗?
-
添加了图片。我看到了很多第三方代码,但这不是我要找的。span>
-
核心图形渐变不直接支持这种渐变。这比使用渐变层或 CGGradient 需要更多的努力。
标签: swift gradient uibezierpath