center-vfl
center-vfl copied to clipboard
Centering a view both in horizontal and vertical
Sometimes, I think there is an another solution, I copied my solution here.
If you want to Horizontal Alignment, just use it
[parentView addConstraint:[NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:parentView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
If you want to Vertical Alignment , just use it
[parentView addConstraint:[NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:parentView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
And this solution works for me, I hope that I share it to someone else.
Yes, your method is actually simpler. Thanks for sharing @VictorZhang2014.
We make progress together. @evgenyneu
Yes 🚀 😄