iOS - Centering view vertically and horizontally using autolayout programmatically
Centering a view using Auto Layout constrains via GUI builder is easy as drinking water. Here some example how to do that programmatically:
[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]];
Written by Noval Agung Prayogo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ios
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#