我正在尝试以编程方式创建如下所示的视图。我相信我需要使用Beizer路径,但是不确定该如何处理路径点?感谢您的帮助
func createShape() -> UIBezierPath {
// create a new path
let path = UIBezierPath()
//Need to determine path points here
}
答案 0 :(得分:2)
有关所需形状的信息,请参阅下面的代码,希望它会对您有所帮助
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)
这是我的输出 interactive mode on