简体   繁体   English

如何在这些Uiimage视图中使用Xcode自动布局?

[英]How to use Xcode auto layout with these Uiimage View?

I'm trying to use auto layout,to make these UiImages views like in the image below, but its always in a mess in one of these devices screens 3.5", 4", 4.7" 我正在尝试使用自动布局,以使这些UiImages视图像下面的图像一样,但在这些设备之一的屏幕3.5“,4”,4.7“中总是混乱不堪

so what I have to do to make it like this ? 所以我要做些什么来使它像这样?

在此处输入图片说明

If you want equal width and equal height of each image then you can add the constraints as shown in below image and if you want to use whole screen space (ie height and width of image will be different) then select all the four pins and select Equal Widths and Equal Heights check box (keep Aspect Ration check box unselected) 如果要使每个图像的宽度相等且高度相等,则可以添加如下图所示的约束,如果要使用整个屏幕空间(即图像的高度和宽度将有所不同),则选择所有四个引脚并选择等宽和等高复选框(未选中保持宽高比复选框) 在此处输入图片说明

I think you are missing some constrains, you can do step by step. 我认为您缺少一些限制,可以逐步进行。 Lets number the imageview for easy reference 让我们为imageview编号以便于参考

imgv1 imgv2 imgv3 imgv1 imgv2 imgv3

imgv4 imgv5 imgv6 imgv4 imgv5 imgv6

imgv7 imgv8 imgv9 imgv7 imgv8 imgv9

imgv10 imgv11 imgv12 imgv10 imgv11 imgv12

Drap and drop imgv1, 2 , 3 to the storyboard and place them adjacent to each other. 将imgv1、2、3拖放到情节提要板上,并将它们彼此相邻放置。 cmd+right click on the three imageview and set constrains(it should be to the nearest neighbour do not forget to untick the checkbox for "from margin"). cmd +右键单击三个imageview并设置约束(应该是到最近的邻居不要忘记取消选中“ from margin”复选框)。 Based on the figure in the question constrains should be 根据图中的问题约束应为

top - 40, left - 20, right - 20. I am assuming that all imageview are of equal height and equal width, in that case select the three imageview and select equal width and equal height constrain. 顶部-40,左侧-20,右侧-20。我假设所有imageview具有相同的高度和宽度,在这种情况下,请选择三个imageview并选择相等的宽度和高度相同的约束。 Dont update the frames yet. 暂不更新框架。 It will show error dont worry we will solve it. 它会显示错误,不要担心我们会解决它。

Now for 2nd, 3rd, 4th row. 现在进入第二,第三,第四行。

Drag and drop the imageview to storyboard and place them as you want ie. 将imageview拖放到情节提要中,然后根据需要放置它们,即。

imgv4,5,6 imgv7,8,9 imgv10,11,12 imgv4,5,6 imgv7,8,9 imgv10,11,12

then select all these imageview(4-12) and add constrains to it. 然后选择所有这些imageview(4-12)并为其添加约束。 The constrains should be 约束应该是

top - 20, left - 20, right - 20 上-20,左-20,右-20

and as all the image view are equal in height and width, select all the imageview that is imgv(4-12) and imgv(1,2,3) and add the constrain equal height and width. 并且由于所有图像视图的高度和宽度均相等,因此选择所有imgv(4-12)和imgv(1,2,3)的图像视图,并添加相等的高度和宽度约束。

There is one more thing missing that is we have to add bottom constrain to the last row ie.(imgv10,11,12) for that select these three imageview and add bottom constrain(remember all constrains are from the nearest neighbor). 缺少的另一件事是,我们必须向最后一行添加底部约束,即(imgv10,11,12),因为要选择这三个imageview并添加底部约束(请记住所有约束都来自最近的邻居)。

Then at last update the frames in the controller. 然后最后更新控制器中的帧。 It should look like the image in the question. 它看起来应该像问题中的图像。

截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM