Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created May 10, 2020 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencurtis/480c28bcfc2077398672f72bb60b73f9 to your computer and use it in GitHub Desktop.
Save stevencurtis/480c28bcfc2077398672f72bb60b73f9 to your computer and use it in GitHub Desktop.
redviewbluetriangle
class RedViewDraw: UIView {
// init from code
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}
// init from xib or storyboard
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupView()
}
override func draw(_ rect: CGRect) {
UIColor.blue.setStroke()
UIColor.blue.setFill()
let bP = UIBezierPath()
bP.move(to: CGPoint(x: 0, y: 0))
bP.lineWidth = 5.0
bP.addLine(to: CGPoint(x: 75, y: 150))
bP.addLine(to: CGPoint(x: 150, y: 0))
bP.addLine(to: CGPoint(x: 0, y: 0))
bP.stroke()
bP.fill()
}
// common setup code
private func setupView() {
backgroundColor = .red
}
}
//in playground we should have a red square
let triangleView = RedViewDraw(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment