AutoLayout In IOS

Kuru Msd
2 min readDec 25, 2019

--

Auto layout is the new user interface developed concept introduce by Apple. It is helps to build a common supported interface for all the devices in ios which is in portrait orientation or landscape orientation. No need to set the view’s constraints for every device. In this article I describe how to build interface using auto layout with coding.

Portait Orientation
Landscape Orientation

Constraints For Using AutoLayout

vertical and horizontal constraints for available for design UI. Vertical constraints can join by another vertical constraints, and horizontal constraints can join by another horizontal constraints.

Horizont Constrains

1. Center X

2. Leading

3. Trailing

4. Width

Vertical Constrains

  1. Center Y
  2. Top
  3. Bottom
  4. Height

Code For Create a view Center of the Device

Masonry is one of the light-weight framework which is used for simplify the auto layout code. This frame work can support both swift and objective- c.

Simplify Above code using Masonry

[view mas_makeConstraints:^(MASConstraintMaker *make) {

make.centerY.equalTo(self.view.mas_centerY);

make.CenterX.equalTo(self.view.mas_CenterX);

make.height.equalTo(@50);

make.width.equalTo(@100);

}]

--

--