Skip to content

Instantly share code, notes, and snippets.

@muhlenXi
Created March 8, 2019 09:12
Show Gist options
  • Save muhlenXi/691327f3a1bc775b047240f7c57b47e7 to your computer and use it in GitHub Desktop.
Save muhlenXi/691327f3a1bc775b047240f7c57b47e7 to your computer and use it in GitHub Desktop.
绘制带弧度的视图
/// 带弧度的 View
public static func createCurveView(frame: CGRect, curveScale: CGFloat, fillColor: UIColor = UIColor.white) -> UIView {
let view = UIView(frame: frame)
view.backgroundColor = UIColor.clear
let finalSize = CGSize(width: UIScreen.main.bounds.size.width, height: frame.size.height)
let layer = CAShapeLayer()
let bezier = UIBezierPath()
bezier.move(to: CGPoint(x:0, y:0))
bezier.addLine(to: CGPoint(x:0, y:finalSize.height))
bezier.addLine(to: CGPoint(x:finalSize.width, y:finalSize.height))
bezier.addLine(to: CGPoint(x:finalSize.width, y:0))
bezier.addQuadCurve(to: CGPoint(x:0,y:0),
controlPoint: CGPoint(x:finalSize.width / 2, y:curveScale))
layer.path = bezier.cgPath
layer.fillColor = fillColor.cgColor
view.layer.addSublayer(layer)
return view
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment