简体   繁体   English

如何使用自动布局来布局水平相等的三个项目

[英]How to Use auto layout to layout three item horizontal equal

As you can see in the screenshot below, I have a static table view cell which contains three UIImageViews. 如您在下面的屏幕快照中所见,我有一个静态表视图单元格,其中包含三个UIImageViews。

I'd like the spacing between the items to be double the spacing between the screen edge and the outer items. 我希望项目之间的间距是屏幕边缘和外部项目之间的间距的两倍。

The spacing should dynamically change depending on screen width (the item size is static). 间距应根据屏幕宽度动态变化(项目大小为静态)。

How can I achieve this using auto layout? 如何使用自动版面实现?

Thanks in advance for your help. 在此先感谢您的帮助。

在此处输入图片说明

Create three holder views, one for each item, they should be placed side wise with width constraint = superview.width / 3 + 0 . 创建三个持有者视图,每个项目一个,应该将它们放置在侧面, width constraint = superview.width / 3 + 0 Then in those three holder views you add your items and set their centerY/centerX to centerY/centerX of holder view 然后在这三个持有人视图中添加您的项目并将其centerY/centerX设置为持有人视图的centerY/centerX

In that way they would have exactly same layout which you want. 这样,它们将具有您想要的完全相同的布局。

在此处输入图片说明

Here's the restriction display as per my comment above. 这是我上面评论中的限制显示。 You can specify the restrictions within the XIB editor. 您可以在XIB编辑器中指定限制。

Add 6 UIView in between the three UIImageView, set constraint that 在三个UIImageView之间添加6个UIView,设置约束

  • all 9 items with same width 所有9个宽度相同的商品
  • and linking the leading and trailing space to zero 并将前尾空间链接为零
  • all 9 items align vertically center 全部9个项目垂直居中对齐
  • set the aspect ratio of the three UIImageView. 设置三个UIImageView的纵横比。

In the screen snapshot below I have added bg colour for those UIWebView to show their existences. 在下面的屏幕快照中,我为那些UIWebView添加了背景色以显示它们的存在。

原型细胞

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

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