Search This Blog

Friday, February 9, 2018

iOS Swift. Difference between leftAnchor and leadingAnchor

When we working with constraint programatically we can have two options for left side: leadingAnchor and leftAnchor, the same for right side: rightAnchor and trailingAnchor.

What is the difference between this anchors?

for left side
self.view.leftAnchor
and
self.view.leadingAnchor

for right side:
self.view.rightAnchor
and
self.view.trailingAnchor

leftAnchor and rightAnchor are strongly fixed and always depend on the left and right sides of the screen. leadingAnchor and trailingAnchor are flexible and depend on the device locale. For locales, where the spelling is from left to right this anchors can be used interchangeably(left with leading and right with trailing). For locales, where the spelling is from right to left leadingAnchor will depend on the right side and trailingAnchor will depend the left side.

For example, you have a screen on which the label is located on the left and textfield on the right for the locale where the writing is from left to right. For a locale where the spelling is from right to left label will be located right and textfield on the left.

You should always use leadingAnchor and trailingAnchor instead of leftAnchor and rightAnchor unless you have special requirements that say that the interface elements are always depend on the left or on the right.

If you want the interface element to be on the screen on the left or right depending on the locale, then use leadingAnchor and trailingAnchor, respectively.

If you want the interface element to always be located on the left or right, regardless of the locale, then use leftAnchor and rightAnchor , respectively.

6 comments:

  1. The most trustworthy poker room in Palm Springs
    The best poker room 거제 출장안마 in 원주 출장샵 Palm Springs · Pokerstars Casino · The PokerStars Poker 밀양 출장샵 Room. Pokerstars PokerStars has been around for a 태백 출장안마 few years now, 수원 출장마사지

    ReplyDelete
  2. There are many articles circulating on internet that exaggerate about Custom Designed Websites. But your article is an exception that made me understand it without any difficulty.

    ReplyDelete
  3. You've written a pretty interesting article. I was on the lookout for information like this. Please share more related information with me so that I can learn more. Best Custom Websites

    ReplyDelete
  4. Thank you Sir, you made it easy as pie. Now i am able to understand and have enough knowledge about this. It is only because of you.
    Custom Designed Websites

    ReplyDelete
  5. This is a great article! Thank you very much. I really need these suggestions. An in-depth explanation is of great benefit. Incredibly inspiring to see how you write. Custom Website

    ReplyDelete
  6. You've written a pretty interesting article. I was on the lookout for information like this. Please share more related information about Mobile Performance Meter Hack with me so that I can learn more

    ReplyDelete