OGeek|极客世界-中国程序员成长平台

标题: ios - 带阴影的线圆 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 14:03
标题: ios - 带阴影的线圆

我正在尝试用带有阴影的笔触颜色绘制一个空圆圈。

let bezierPath              = UIBezierPath(ovalIn: CGRect(x: 80, y: 200, width: 100, height: 100))

let shapeLayer              = CAShapeLayer()
shapeLayer.path             = bezierPath.cgPath
shapeLayer.fillColor        = UIColor.clear.cgColor
shapeLayer.strokeColor      = UIColor.white.cgColor
shapeLayer.lineWidth        = 3
shapeLayer.shadowPath       = bezierPath.cgPath
shapeLayer.shadowColor      = UIColor.black.cgColor
shapeLayer.shadowOffset     = CGSize(width: 0, height: 0)
shapeLayer.shadowOpacity    = 1

containerView.layer.addSublayer(shapeLayer)

The result

但是阴影填满了整个圆圈。如何去掉它并保留外阴影?



Best Answer-推荐答案


只要省略设置shapeLayer.shadowPath,你会得到这样的东西(图层的标准阴影,基本上就是图层的不透明部分):

enter image description here

关于ios - 带阴影的线圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39349201/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) Powered by Discuz! X3.4