Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override requiresConstraintBasedLayout in UIView using Swift 3?

In the UIView, docs, it is stated that you must override requiresConstraintBasedLayout to return true in your custom view if if needs constraints to work.

How do you do this using Swift 3?

like image 337
Simon Epskamp Avatar asked Mar 01 '17 11:03

Simon Epskamp


2 Answers

Use the following syntax for overriding the getter:

override open class var requiresConstraintBasedLayout: Bool {
    get {
        return true
    }
}
like image 180
Simon Epskamp Avatar answered Nov 07 '22 02:11

Simon Epskamp


To override the requiresConstraintBasedLayout getter you can simply use:

override open class var requiresConstraintBasedLayout: Bool {
    return true
}
like image 26
Luc Dion Avatar answered Nov 07 '22 01:11

Luc Dion