Skip to content

Instantly share code, notes, and snippets.

@collinsrj
Last active August 29, 2015 14:21
Show Gist options
  • Save collinsrj/967c4948b7c7a1866770 to your computer and use it in GitHub Desktop.
Save collinsrj/967c4948b7c7a1866770 to your computer and use it in GitHub Desktop.
An Xcode playground showing a custom UIView
import UIKit
import XCPlayground
class MyView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
override func drawRect(rect: CGRect) {
let path = UIBezierPath()
path.moveToPoint(CGPoint(x: 10, y: 10))
path.addLineToPoint(CGPoint(x: 100,y: 10))
path.addLineToPoint(CGPoint(x: 100,y: 100))
path.addLineToPoint(CGPoint(x: 10, y: 100))
path.closePath()
UIColor.redColor().setStroke()
path.lineWidth = 3
path.stroke()
}
func setup() {
backgroundColor = UIColor.whiteColor()
}
}
let myView = MyView(frame: CGRect(x: 0, y: 0, width: 200, height: 300))
XCPShowView("Demo Square", myView)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment