Skip to content

Instantly share code, notes, and snippets.

@pallavtrivedi03
Created December 11, 2021 16:31
Show Gist options
  • Save pallavtrivedi03/9d97ebeb139a8399399282b70fc9f13d to your computer and use it in GitHub Desktop.
Save pallavtrivedi03/9d97ebeb139a8399399282b70fc9f13d to your computer and use it in GitHub Desktop.
class BoardingPassView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupView()
}
func setupView() {
let path: UIBezierPath = getPath()
let shape = CAShapeLayer()
shape.path = path.cgPath
shape.lineWidth = 2.0
shape.strokeColor = UIColor.white.cgColor
shape.fillColor = UIColor.clear.cgColor
self.layer.addSublayer(shape)
}
func getPath() -> UIBezierPath {
let path: UIBezierPath = UIBezierPath()
path.move(to: CGPoint(x: 50, y: 10))
//Top Edge
path.addLine(to: CGPoint(x: 260, y: 10))
//Right Top Curve
path.addArc(withCenter: CGPoint(x: 260, y: 50), radius: 40, startAngle: CGFloat(Double.pi/2 * 3), endAngle: 0, clockwise: true)
//Right Edge
path.addLine(to: CGPoint(x: 300, y: 300))
//Semicircle on Right Edge
path.addArc(withCenter: CGPoint(x: 300, y: 320), radius: 14, startAngle: CGFloat(Double.pi/2 * 3), endAngle: CGFloat(Double.pi/2), clockwise: false)
//Right Edge second half
path.addLine(to: CGPoint(x: 300, y: 450))
//Right bottom curve
path.addArc(withCenter: CGPoint(x: 260, y: 450), radius: 40, startAngle: CGFloat(0), endAngle: CGFloat(Double.pi/2), clockwise: true)
//Bottom Edge
path.addLine(to: CGPoint(x: 50, y: 490))
//Left bottom curve
path.addArc(withCenter: CGPoint(x: 50, y: 450), radius: 40, startAngle: CGFloat(Double.pi/2), endAngle: CGFloat(Double.pi), clockwise: true)
//Left second half
path.addLine(to: CGPoint(x: 10, y: 340))
//Semicircle on left edge
path.addArc(withCenter: CGPoint(x: 10, y: 320), radius: 14, startAngle: CGFloat(Double.pi/2), endAngle: CGFloat(Double.pi/2 * 3), clockwise: false)
//Left Edge
path.addLine(to: CGPoint(x: 10, y: 50))
//Left Top Curve
path.addArc(withCenter: CGPoint(x: 50, y: 50), radius: 40, startAngle: CGFloat(Double.pi), endAngle: CGFloat(Double.pi/2 * 3), clockwise: true)
//Moving to the semicircle
path.move(to: CGPoint(x: 24, y: 320))
//Line from left semicircle to right
path.addLine(to: CGPoint(x: 286, y: 320))
path.close()
return path
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment