Place a view to the centre of the layout in iOS Autolayout

By | March 10, 2017

Below code explains how you can place a view to the centre of the layout using Autolayout in iOS.


[self.view addConstraint:
 [NSLayoutConstraint constraintWithItem:self.view
                     attribute:NSLayoutAttributeCenterX
                     relatedBy:0
                     toItem:view
                     attribute:NSLayoutAttributeCenterX
                     multiplier:1
                     constant:0]];

[self.view addConstraint:
 [NSLayoutConstraint constraintWithItem:self
                     attribute:NSLayoutAttributeCenterY
                     relatedBy:0
                     toItem:view
                     attribute:NSLayoutAttributeCenterY
                     multiplier:1
                     constant:0]];

Leave a Reply

Your email address will not be published.