当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - auto layout not working properly for image view and label when both are align together

问题描述:

I want to align image view and label horizontally in container but they are aligning correctly

I want to make both leading edges together but it not showing correctly

and one more thing if a view present there below label and if text is less or more than it should display just below the label height

view should adjusted according to variant height of label

网友答案:

Assuming that your layout looks something like this, at the top there is a image, below that there is a label whose leading should be equal to the top image view leading. And below the label there should be another view whose top space should vary according to the label height.

Solution for this goes like this, For the top image view pin image view to top of its superview with some space as per your requirements and centre it horizontally. For the label pin it to image view bottom and label top with some space as per your requirements. Also add constraint to leading of label to leading of top image view and trailing of label to trailing of image view as 0 points. For the view below the label pin label bottom to view top with some space as per your requirements. Then add leading and trailing constraints with respect to top image view similar to the constraints added to the label trailing and leading.

分享给朋友:
您可能感兴趣的文章:
随机阅读: