Last active
October 10, 2016 13:31
-
-
Save gtempesta/955c4847f0d1e22751b82e602041b990 to your computer and use it in GitHub Desktop.
Easiest way to draw a Rectangle in swift 3.0
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
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