I\'m trying to position 2 UIImage views in the center of the screen, side by side. If it\'s just 1 UIImage, I can just set them to be vertically and horizontally center in the c
An elegant way to solve this is to apply constraints on UIImageView
itself.
Now think that if you need to have both the image views in superview's
centre then one imageView
should have it's trailing
edge at the centre of superview
and another should have a leading
edge at the centre.
Control-Click
on imgvLeft
and drag it to superview
, you will see some constraint option to select; choose trailing
edge constraint. Now go to that constraint and click it you will see details as shown in picture below. Change the second item
from trailing
to centreX
and keep the constant 0.
Same way you can apply the leading
constraint on imgvRight
and change the second item
to centreX
.
Now if you wish to keep some distance between both the views then you can change the constant value in constraints. For example if you need an spacing of 20 px
then change the constant to spacing/2 i.e. 10.