Reputation: 563
How to add uiview and make it the self view center using autolayout and without setting frame or center property.
I know that we can set like this
view.center = window.center;
or
view.center = self.view.center;
but i want to set to the center of the view to self view center using autolayout.
Upvotes: 0
Views: 471
Reputation: 165
You can do this with storyboard you don't need to write any code. Use Size Inspector and remove all the line in Autosizing part.
Upvotes: 0
Reputation: 367
You should be adding 4 constraints to your view then:
You can create constraints in code like this, and add them to your view:
[NSLayoutConstraint constraintWithItem:label
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:tab
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0];
Upvotes: 1