Content hugging priority Dynamic Cell Size

最后都变了- 提交于 2019-12-12 06:16:11

问题


Recently I've had a complex auto layout situation that has been solved (thanks to @Catalina T.). Currently I'm experiencing an issue with Content Hugging Priority. I have 4 dynamic labels that may contain huge texts so cells should fit the content. With the current constraints and priorities if I set huge texts to all dynamic labels it works perfectly (though one of them won't be displayed fully instead it will be clipped with dots). If I set the third label's text to a huge one auto layout goes crazy... I get something like this:

Whereas I want all the labels to be arranged consequently.

Demo project.

How to fix this issue?

Thank you in advance!


回答1:


I managed to solve this issue.

AutoLayout should know leading, trailing, top and bottom constraints from all your dynamic views. Besides that it might happen that one view is huge and others are not, as a result you'll get the wrong arrangement. To solve this simply add Vertical Spacing for each dynamic views that are not yet connected with this constraint. Then you should change the constraint Relation to Greater Than Or Equal, so you'll simply notify the AutoLayout that you want these views to be arranged consequently.

Solved demo project.



来源:https://stackoverflow.com/questions/30276663/content-hugging-priority-dynamic-cell-size

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