I was wondering, now with Auto Layout you have to tell every UIView that you don't want to translate its (deprecated) auto-resizing masks to layout constraints like so:
let view = MyView()
view.setTranslatesAutoresizingMaskIntoConstraints(false)
In my app, I do (almost) all my views with custom constraints so I never want automatic translation of auto-resizing masks. Wouldn't it be nice if the default setting for this would be false? So only in situations where I DO want translation of auto resizing masks I set it to true?
Is there a way to make false the default for setTranslatesAutoresizingMaskIntoConstraints? Maybe with a clever extension (a.k.a. category) of some sort?
I fully agree which is why I made this category which includes such an initialiser:
extension UIView {
// MARK: Initializing a View Object
/**
* @name Initializing a View Object
*/
/**
* Returns a frameless view that does not automatically use autoresizing (for use in autolayouts).
*
* @return A frameless view that does not automatically use autoresizing (for use in autolayouts).
*/
class func autoLayoutView() -> Self {
let view = self()
view.setTranslatesAutoresizingMaskIntoConstraints(false)
return view
}
}
There is a swift branch in the project as well, but this is very early stage. Pull requests welcome!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With