To autolayout or NOT to autolayout? That is the question …

Autolayout is a cool feature Apple introduced several years ago which transforms the way in which developers think about laying out their views. In short, autolayout is incredibly easy to set up and use with Interface Builder – but quite a pain in the neck when doing so in Objective-C code.

For those of us code purists that refuse to use Interface Builder – the question remains – to use autolayout or NOT to use autolayout? Should we just continue to set the frame of each view and simply set the autoresizing mask when the view needs to be adjusted dynamically? After all, adding and removing constraints is a real pain, so why not just set the frame and have a nice day?

My answer is the following: always do what is simplest and works best – the path of least resistance is the golden path. In some cases, the extra overhead of laying out views with autolayout in code is actually worth it! This applies for universal apps with a responsive design that must adjust to screen rotation (portrait and landscape mode). But for those apps that only support one screen orientation on a single device type, it may be simpler to set the frame in code.

Leave a Reply