我正在尝试以编程方式创建如下所示的视图。我相信我将需要使用Beizer路径,但不确定如何处理路径点?任何帮助表示赞赏
func createShape() -> UIBezierPath {
// create a new path
let path = UIBezierPath()
//Need to determine path points here
}
最佳答案
对于您需要的形状,请参考波纹管代码,希望它将对您有所帮助
let view = UIView(frame: CGRect(x: 50, y: 100, width: 200, height: 300))
let path = UIBezierPath()
path.move(to: CGPoint(x: 0.0, y: 200))
path.addCurve(to: CGPoint(x: 200, y:150),
controlPoint1: CGPoint(x: 50, y: 350),
controlPoint2: CGPoint(x:150, y: 0))
path.addLine(to: CGPoint(x: view.frame.size.width, y: view.frame.size.height))
path.addLine(to: CGPoint(x: 0.0, y: view.frame.size.height))
path.close()
let shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
view.backgroundColor = UIColor.black
view.layer.mask = shapeLayer
self.view.addSubview(view)
这是我的输出
关于ios - 在iOS中以波形切割 View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52035801/