【发布时间】:2018-12-15 15:40:45
【问题描述】:
我有一个加号 (+),目前是蓝色的,但我想让它透明,以便用户可以看到背景。加号层被添加到更大的视图中。将加号图层设置为clear颜色并不能解决问题。
class AddButtonView: UIView {
...
private func setupPlusLayer() {
let path = UIBezierPath()
path.move(to: CGPoint(x: plusButton.frame.midX, y: plusButton.frame.midY-20))
path.addLine(to: CGPoint(x: plusButton.frame.midX, y: plusButton.frame.midY+20))
path.move(to: CGPoint(x: plusButton.frame.midX-20, y: plusButton.frame.midY))
path.addLine(to: CGPoint(x: plusButton.frame.midX+20, y: plusButton.frame.midY))
path.usesEvenOddFillRule = true
let shapeLayer = CAShapeLayer()
shapeLayer.fillRule = .evenOdd
shapeLayer.path = path.cgPath
shapeLayer.strokeColor = UIColor.blue.cgColor
shapeLayer.fillColor = UIColor.blue.cgColor
shapeLayer.lineWidth = 4
// Add that `CAShapeLayer` to your view's layer:
self.layer.addSublayer(shapeLayer)
}
}
如何使加号透明?
【问题讨论】:
-
什么是加号按钮层?也许应该是 self.layer add shapelayer
-
@agibson007 谢谢,已编辑
标签: ios swift cashapelayer cgrect