Skip to content

Instantly share code, notes, and snippets.

@gtempesta
Last active October 10, 2016 13:31
Show Gist options
  • Save gtempesta/955c4847f0d1e22751b82e602041b990 to your computer and use it in GitHub Desktop.
Save gtempesta/955c4847f0d1e22751b82e602041b990 to your computer and use it in GitHub Desktop.
Easiest way to draw a Rectangle in swift 3.0
import UIKit
import XCPlayground
import PlaygroundSupport
public class SimpleLine: UIView {
public init() {
super.init(frame: CGRect(x: 0, y: 0, width: 480, height: 320))
backgroundColor = UIColor.white
}
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
let boundingRect = CGRect(x: 220, y: 100, width: 80, height: 80)
context!.setStrokeColor(UIColor.black.cgColor)
context!.setFillColor(UIColor.darkGray.cgColor)
context!.fill(boundingRect)
context!.stroke(boundingRect, width: 4.0)
}
}
let firstLine = SimpleLine()
PlaygroundPage.current.liveView = firstLine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment