小编Min*_*008的帖子

协议扩展中的"自我"是什么?

我看到了很多以下格式的例子

extension Protocolname where Self: UIViewController
Run Code Online (Sandbox Code Playgroud)

什么是where Self协议扩展.我找不到关于此的文档.

protocols swift swift-extensions swift-protocols

20
推荐指数
3
解决办法
2万
查看次数

使用 UIBezierPath 用渐变色填充圆形边框

我想使用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)
Run Code Online (Sandbox Code Playgroud)

编辑:添加了图像。我想实现这样的目标。在此处输入图片说明

gradient uibezierpath swift

1
推荐指数
1
解决办法
1266
查看次数