ios - 带阴影的线圆
<p><p>我正在尝试用带有阴影的笔触颜色绘制一个空圆圈。</p>
<pre><code>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)
</code></pre>
<p> <a href="/image/w1y6u.png" rel="noreferrer noopener nofollow"><img src="/image/w1y6u.png" alt="The result"/></a> </p>
<p>但是阴影填满了整个圆圈。如何去掉它并保留外阴影?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>只要省略设置<code>shapeLayer.shadowPath</code>,你会得到这样的东西(图层的标准阴影,基本上就是图层的不透明部分):</p>
<p> <a href="/image/j1AyD.png" rel="noreferrer noopener nofollow"><img src="/image/j1AyD.png" alt="enter image description here"/></a> </p></p>
<p style="font-size: 20px;">关于ios - 带阴影的线圆,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39349201/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39349201/
</a>
</p>
页:
[1]