Auto layout: A friend or a foe? / Tips and tricks

This is the 2nd of the 2 part series for Auto Layout

--

Before I start with this week’s article I want to give some information about why I couldn’t upload an article the previous Sunday. With all the Iris announcements(I joined Iris) I didn’t have the time to review my draft properly and publish it. Also I don’t like to publish something that I don’t like to read myself.

I’m the only one with a dock for my iPhone on the desk? 😇😂

I already said that I really like Auto Layout. I started this 2 part series talking about the advantages that I think this technology has. Many of you already know that in this part I will share with you some of my favourite tips and tricks that I think will boost your workflow.

Stack Views

If you don’t know already, stack views introduced with iOS 9 and is one of my favourite things to use when I Auto Layout. Let me explain. For example, you have a photo and a label and you want to align them. A great solution would be to use stack views. After that you will have to consider adding constraints to a single thing inside your VC (stack view) and not 2 of them. (Image and label)

Use the + button left to the font or color attribute

It’s easier than ever to make your app adaptive and create a wonderful experience for your users. When it comes to fonts, the resolution for the iPad needs a bigger font size than the resolution for the iPhone. You can easily go to to font picker press the add button and create a second font attribute for a specific size class. Yay 🎉 P.s For better adaptivity use the system font. It’s the SF font and it’s really useful when you want to add accessibility support to your app.

Color and font attribute

Focus on a specific set of devices

When you start with an idea and you want to “import” designs in Xcode and make the app adaptive., I highly suggest that first you need to focus on a specific set of devices (e.g iPhones) and then iPads. It can save you a lot of time when it comes to Auto Layout. You will be more organized and efficient.

Avoid the margin option

I will also highly suggest to avoid any option that contains Margin. It can really mess up your layout and constraints. Also after that you will searching about what’s going wrong with your constraints/ layout and the reason I talked above will be one of the reasons that will make you to stay up all night wondering what’s going on.

I couldn’t be happier with Auto Layout and how it helped me over the years to create my layouts with ease. Above you read my favourite tips and tricks. Don’t “be afraid” with Auto Layout and embrace it.

I hope that you enjoyed the read and that you learned a little more about Auto layout and some tricks behind this technology. Until next time, have an awesome week and keep coding.

If you enjoyed reading this entry, please hit the 💚 button.

--

--

Tsaraboulidis Agisilaos
The adventures Of An iOS Developer

Co-Founder and CTO @irisapp. prev: iOS eng intern @Microsoft. Makes @soundmemoryrush. Photographer. I like traveling. Nerd. 22.