Skip to content

Instantly share code, notes, and snippets.

@algera
Created February 13, 2019 22:35
Show Gist options
  • Save algera/af4e56405e7d0d62507443506106bdc2 to your computer and use it in GitHub Desktop.
Save algera/af4e56405e7d0d62507443506106bdc2 to your computer and use it in GitHub Desktop.
//
// Transparent Triangle in Swift 4.2
// (c) 2019 by Jeff Algera
// MIT License
//
class TransparentTriangleView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
isOpaque = false
backgroundColor = UIColor.clear
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func draw(_ rect: CGRect) {
guard let context = UIGraphicsGetCurrentContext() else { return }
context.clear(rect)
context.beginPath()
context.move(to: CGPoint(x: rect.maxX, y: rect.minY))
context.addLine(to: CGPoint(x: rect.minX, y: rect.maxY))
context.addLine(to: CGPoint(x: rect.minX, y: rect.minY))
context.closePath()
context.setFillColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0667)
context.fillPath()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment