XCode 7 Autolayout Constraints: How to make 2 images stay horizontally in the center

2 Solutions Collect From Internet About “XCode 7 Autolayout Constraints: How to make 2 images stay horizontally in the center”

Take a view, put both the images inside that view. Add the constraints on those images with respect to the view you made (Edge to edge to the view). Now add the constraints on the view in respect of the super view. (Center vertically and horizontally). That’s it!

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.

enter image description here