Created
June 17, 2022 18:19
-
-
Save gavi/d928612e8f0aa8dc5e88d2562e996a32 to your computer and use it in GitHub Desktop.
Draw by overriding draw on UIView
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 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 |
Author
gavi
commented
Jun 17, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment