Lucas
Lucas

Reputation: 776

how to override draw(rect ) function in UIView Swift?

if I want to create a custom UIView with a custom shape I should override draw function right?

but I don't understand how it works it has no return values where should I send my bezier path to?

override func draw(_ rect: CGRect) {
// after I create my bezier path what should I do inside to have my custom view drawn?

}

thank you in advance for the anwers

Upvotes: 2

Views: 5122

Answers (1)

matt
matt

Reputation: 536047

Fill/stroke the path. Example:

class MyView1 : UIView {
    override func draw(_ rect: CGRect) {
        let p = UIBezierPath(ovalIn: CGRect(x:0,y:0,width:100,height:100))
        UIColor.blue.setFill()
        p.fill()
    }
}

Upvotes: 5

Related Questions