Multi Line Labels and an Image with UIStackView

≡放荡痞女 提交于 2020-01-06 08:13:53

问题


I am trying to see if I can easily use a UIStackView to create multi line labels and also display an image.

Here are my current constraints.

When I run it I get the following:

If I remove the imageview then the multi line works. Somehow UIImageView width and height is messing up everything. What am I doing wrong?


回答1:


Change height and width of the imageView to give proper look and don't give fixed height for the stackview, only give top, bottom, leading and trailing.

THis is how it will look like




回答2:


StackView does not really work well with constraints, as they kind of destroy the purpose of stack views. Since the vertical inner stackView is inside a horizontal stackView with the imageView. When you give imageView hard constraints, in order to satisfy these constraints and keep the height & width values of stackViews at same level with imageView and inner stackView, the inner stackView cannot expand and it's height and you cannot get the behaviour you want. So as also mentioned in the comments, it is better to achieve your design without stackViews.

PS: I'm not saying stackViews cannot be used with constraints in their subViews. It can be done, and sometimes allow programmers to successfully achieve their goal, but you will always get debugger warnings due to conflicting constraints about the views with constraints inside a stackView.



来源:https://stackoverflow.com/questions/54028617/multi-line-labels-and-an-image-with-uistackview

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