Center 4 images with startup restrictions

I'm new to autorun, and I'm a little fixated on how to center these 4 images on all different devices, like images. I tried to apply automatically configured restrictions, but then it will have such a distance and is not suitable for all devices. So my question is, what restrictions do I need to apply on all different images in order to make the whole image centered with the same distance?

Here's what my cell looks like in storyBoard:

enter image description here

Image of restriction parameters on image 1:

enter image description here

simulator image:

enter image description here

/// MY TRY ////

Here you can see the limitations that I added and the result?

enter image description here

result:

enter image description here

+7
ios objective-c iphone autolayout swift
source share
4 answers

Your approach is almost right, it just has no size restrictions for images.

If you want to dynamically resize images and maintain a constant space between them, set image limits for width >=20 (or any other value, depending on your needs) and a limit to maintain aspect ratio. Then ctrl-drag from UIImageView1 to UIImageView2 and set a limit for equal width. Repeat this from UIImageView1 to UIImageView3 and from UIImageView1 to UIImageView4 .

enter image description here


If you want the images to always keep their fixed sizes and spaces with a dynamic size between them, you need a different approach:

The trick here is to place 3 empty UIViews between UIImageViews so that it looks like this:

enter image description here

  • Set vertex constraints for all views
  • Set left and right constraints for UIImageView1 and 4
  • Set limits for all UIImageViews with the same width
  • Set limits for all UIView between UIImageViews with the same width
  • Set limits for all distances between views to 0
  • Set width limits for UIViews at >= 0

Thus, empty UIViews between UIImageViews change dynamically and everything is the same.

Hope you have an idea.

+6
source share

For the first image, add a leading space for viewing and for the last image add a trailing space for viewing and add the vertical distance between the first and second, second and third, third and fourth, and also set the horizontal center inside the container for each image

0
source share

For objects on your storyboard, at least 4 restrictions are required for each object .

When orange lines appear around your UIImageView object in your question, this means that the constraint is missing or conflicting and often means that the image does not appear at runtime as you expected.

In the first case, I recommend that you select all objects and "clear restrictions", and then start again.

Although this is not quite the same, here is a link to the answer, which explains in more detail the limitations of the auto market. Once you understand this, a car dealership can be very powerful.

→ Link to a similar problem of automatic layout - iOS CustomTableViewCell: elements that are not correctly aligned <<

I hope this helps

0
source share

If you want the images to always keep their fixed size and spaces with a dynamic size between them, then a very simple way to first drag four UIViews to your StoryBoard set restricts the top left right and high-altitude for all UIViews and gives equal width to all UIViews (dragging from one UIView to another and sets the repeat width of this work to equal for all UIView).

Image about layouts

Secondly, you need to drag and drop your images installed in these UIViews and set their width to the height of the constraint and central horizontal in the container and vertically vertically in the container.

In the last background color set for all UIViews by default (white) you get the result, which it will work .... I assure you.

Xcode screenshot

0
source share

All Articles