如何在iOS中相交于层
我有一个加号(+),当前是蓝色的,但我想让它透明,这样用户就可以看到背景。加号图层将添加到更大的视图中。将加号图层设置为如何在iOS中相交于层,ios,swift,cashapelayer,cgrect,Ios,Swift,Cashapelayer,Cgrect,我有一个加号(+),当前是蓝色的,但我想让它透明,这样用户就可以看到背景。加号图层将添加到更大的视图中。将加号图层设置为clearcolor并不能解决问题 class AddButtonView: UIView { ... private func setupPlusLayer() { let path = UIBezierPath() path.move(to: CGPoint(x: plusButton.frame.midX, y: plus
clear
color并不能解决问题
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)
}
}
如何使加号透明?尝试使用带+的.png图像使其透明。这样可以很好地工作,您无需绘制加号。您可以通过以下方式实现此目的:
CAShapeLayer
(circleShape
)李>
反转
)。对于这种情况,您需要一个具有完全相同的圆路径和加号路径的CGMutablePath
。另外,不要忘记设置inversed.fillRule=.evenOdd
李>
plusShape
)李>
圆形
作为视图层的子层李>
circleShape.mask=inversed
李>
plusShape
作为子层添加到视图的层中能够通过编程方式绘制加号以节省空间并使应用程序具有分辨率,这将是非常酷的。这将是非常酷的,但在我看来,如果没有这样好的结果,这将是大量的工作。加号按钮层是什么?也许应该是self.layer添加shapelayer@agibson007谢谢,编辑