Reputation: 515
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
Last image scaled too much
When Equally width is set
Constraints Setting
Upvotes: 0
Views: 503
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
Reputation: 4218
You need extra views to achieve this
In the sample picture the red rectangles they are all invisible UIView
with constraints:
fixed length leading space to the view on the left(or the superview)
fixed length trailing space to the view on the right(or the superview)
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