问题
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