I'm writing nib-less views in which I use autolayout for all my layout logic. I find myself having to turn off autoresizing with every view I instantiate. My code is littered with a lot of these:
view.translatesAutoresizingMaskIntoConstraints
Ideally I'd like to just
extension UIView/NSView {
override var translatesAutoresizingMaskIntoConstraints: Bool = false
}
and get it over with once and for all, but extensions can't override stored properties.
Is there some other simple way to switch off autoresizing for good?
Well just a suggestion since its annoying to always set that to false, just setup a function with all the shared setups for the
UIViewand call it every time, its saves time and its kinda less annoying than trying and setting the values each time,You can't
overridethis constraints properties because theUIViewmaybe declared in theIBtranslatesAutoresizingMaskIntoConstraints according to apple.
imagine if you could
overridethat from anextensionthat would lead to some conflicts if there was otherUIView's that's have the opposite valueTrue || false, so in my opinion:Please if anyone have additional information, don't hesitate to contribute.
UPDATE: I found this cool answer that could also work, check out the code below.
So simply just create
MyNiblessinstance asUIViewand this also open big door to customizations too