Last active
October 10, 2016 13:31
-
-
Save gtempesta/48f3c9ab7561d52e9248412dbb16a3ab to your computer and use it in GitHub Desktop.
Easiest way to draw a line in swift 3.0
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
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() | |
context!.setLineWidth(4.0) | |
context!.setStrokeColor(UIColor.darkGray.cgColor) | |
context!.move(to: CGPoint(x: 100, y: 100)) | |
context!.addLine(to: CGPoint(x: 300, y: 300)) | |
context!.strokePath() | |
} | |
} | |
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