Skip to content

Instantly share code, notes, and snippets.

@gavi
Created June 17, 2022 18:19
Show Gist options
  • Save gavi/d928612e8f0aa8dc5e88d2562e996a32 to your computer and use it in GitHub Desktop.
Save gavi/d928612e8f0aa8dc5e88d2562e996a32 to your computer and use it in GitHub Desktop.
Draw by overriding draw on UIView
import UIKit
import PlaygroundSupport
class Rectangle:UIView{
override func draw(_ rect: CGRect) {
let path = UIBezierPath(rect: rect)
path.move(to: CGPoint(x:0,y:rect.height))
path.addLine(to: CGPoint(x:rect.width/2,y:rect.height/1.4))
path.addLine(to: CGPoint(x:rect.width,y:rect.height))
UIColor.red.setStroke()
path.stroke()
}
}
let rect=Rectangle(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
PlaygroundPage.current.liveView = rect
@gavi
Copy link
Author

gavi commented Jun 17, 2022

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment