Forked from pallavtrivedi03/BoardingPassView.swift
Created
February 11, 2022 18:14
-
-
Save EvolverSwiftUI/fe7b98b43e9edbfe16b2721b43aee7b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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