iosuiimageviewautolayoutnslayoutconstraint

Uiimageview autolayout issue


I have this images views:

enter image description here

I want that for every device that the distance between the first imageview and the left side it's the same , then the distance between the first imageview and the second image view it's the same and the distance between the second imageview and the right border it's the same. Essentially It must grow their width according to the screen size of the device , but I don't be able to do this by autolayout on storyboard.

Can you help me?


Solution

  • Try the auto layout in below mentioned way

    Suppose your two image views are imageVw1 and imageVw2 Consider imageVw1 is left one.

    So put following constraints for imageVw1

    1. Leading constraint with main container view.
    2. Vertical constraint with main container view.
    3. Fixed height Constraint.
    4. Horizontal constraint to imageVw2.

    Similarly constraint for imageVw2

    1. Trailing constraint with main container view.
    2. Vertical constraint with main container view.
    3. Fixed height Constraint.
    4. Horizontal constraint to imageVw2.

    IMPORTANT : Provide equal width constraint to both imageView. (this constraint is for assigning equal width for both the image view. Else we need to give variable width, but i guess you need both image would be of equal width. So just assign equal width constraint).

    See output for 6sPlus and 5s.

    Screenshot for 6sPlus device

    Screenshot for 5s device