Autolayout causing UILabel to resize with unwanted padding

只谈情不闲聊 提交于 2020-01-17 03:09:33

问题


I have a customized UITableViewCell that has an image on the left and two UILabels on the right. The top edge of the first label is horizontally aligned with the top of the image, and the second label has its bottom edge aligned with the bottom of the image.

The second label displays a larger content and I'm hoping that it could resize vertically to show more content but it should not interfere with the top label(for which I've set a vertical spacing constraint between the top label and the Content Label).

The preferred width for the Content label is set to automatic and its content hugging priority is set higher than the vertical spacing constraint. It has has a lower content compression resistance priority.

If I put in some text that requires more than one line to display, the Content label will resize and does not interfere with the top label, but it adds this weird padding to the top and bottom of the label.

If I remove the vertical spacing constraint between the two labels the padding would disappear but the Content label would overrun the top label.

Is there a way to fix this so that the Content label would have its bottom aligned with the bottom of the image and resize without adding these paddings?


回答1:


Try implementing your constraints programmatically using a library like Masonry. You'll have far better control over your UI elements, and a better understanding of how the constraints work.



来源:https://stackoverflow.com/questions/28326688/autolayout-causing-uilabel-to-resize-with-unwanted-padding

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