Auto layout issue with a row of image views

只谈情不闲聊 提交于 2019-12-12 03:33:16

问题


This is driving me nuts!

I am trying to show a row of images of followers to a profile in my app. The idea is for it to be 5 images where you could theoretically click on them and move to their profile.

Here is what I am having troubles with now :

I've never had to ask about auto layout before so I don't know what to show you all for your help. Is feel like this is a silly problem...

Here is the setup:

  • Designed in a separate XIB
  • All elements are encapsulated in a UITableViewCell

Any help would be appreciated.

EDIT: So as per Michal I tried a stack view and although it seemed like the right thing to do it honestly gave me the same results, so I am sure I am doing this wrong. Please see images below


回答1:


I figured I would make this an answer so that the comments don't get too long. So, with everything these are the constraints you should have added:

1) Set all UIImageView's to have equal widths

2) Set all UIImageView's aspect ratio constraint

3) Add a height constraint to each UIImageView

4) Set all UIImageView's to have equal heights, just like with width in step 1

5) Set leading and trailing space constraints for each UIImageView. This one is a little tricky. The first UIImageView should have a leading constraint = x. The last UIImageView should have a trailing constraint = x. The constraints between each UIImageView should be >= x.

This is the icon for selecting constraints:



来源:https://stackoverflow.com/questions/35442912/auto-layout-issue-with-a-row-of-image-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!