Created
May 10, 2020 08:51
-
-
Save stevencurtis/480c28bcfc2077398672f72bb60b73f9 to your computer and use it in GitHub Desktop.
redviewbluetriangle
This file contains 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 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