Alvin
Alvin

Reputation: 515

Align multiple images equally in different screen size

I am having troubles aligning multiple images by using auto-layout in xcode.
I tried different settings, but nothing seems to work yet (refer to attached photos).

It would be great to hear some opinions from you guys, either in code or storyboard.

I want the image to be aligned equally in different screen sizes.

Too much space

enter image description here

Last image scaled too much

enter image description here

When Equally width is set enter image description here

Constraints Setting enter image description here

Upvotes: 0

Views: 503

Answers (2)

Azat
Azat

Reputation: 6795

For left most item you should specify leading space to superview, for right most specify trailing space to superview. For all inner gaps between views specify horizontal spacing and for each neighbor view specify equal width constraint. Additionally I recommend for you to specify Align center Y for all views and set the y position constraint only for one of them

Upvotes: 0

dopcn
dopcn

Reputation: 4218

You need extra views to achieve this

example

In the sample picture the red rectangles they are all invisible UIView with constraints:

  1. fixed length leading space to the view on the left(or the superview)

  2. fixed length trailing space to the view on the right(or the superview)

  3. fixed length height

This way it's the invisible views who have different width in different screen size while the size of images between them is fixed.

Upvotes: 1

Related Questions