Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 8 : Auto layout Leading & Trailing

I started iOS development a week ago and I'm currently learning AutoLayout. and sadly I can't wrap my head around the Leading & Trailing constraints and when to use them, I don't even understand them at all. I have done some research and I'm just actually more confused now. Can someone give some examples?

This definition is form the Apple website:

The values increase as you move towards the trailing edge. For a left-to-right layout directions, the values increase as you move to the right. For a right-to-left layout direction, the values increase as you move left.

https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/AnatomyofaConstraint.html

Thanks

like image 672
John Avatar asked Oct 30 '25 08:10

John


1 Answers

TL;DR

They couldn't just name it left and right because it had to make sense in both layout orientations: left-to-right and right-to-left. Hence Trailing and Leading.

Longer Answer

I think the question you're asking yourself is why the heck Apple is not just naming it left and right. What's with the trailing and leading.

The reason behind this is that there might be 2 different layouts. Starting with iOS 9, the UI layout for left-to-right languages (like English) is.. well left-to-right. But in case of Arabic for example, it's right-to-left.

However Autolayout is smart enough that you don't need to setup your layout twice for these 2 types of layouts. You just set it up once and the system auto-inverts it in case your app supports right-to-left languages.

like image 124
Sergey Katranuk Avatar answered Nov 02 '25 00:11

Sergey Katranuk