我试图在我的表格视图单元格中显示一些内容。 我在左边有一张图片,我必须在右侧显示一些文字(说明)。 一切都是动态的。 所以描述的长度有时很小,有时非常大。
现在,我在左侧有一个图像视图,在右侧有说明。请查找下面的图像以供参考
。
如果描述在图像视图之后滑落,我想要显示描述占据整个tableview单元格宽度。 我怎样才能做到这一点?
I am trying to show some content in my Table view cell. I have an image on the left and I have to show some text (Description ) on the right. Everything is dynamic. So the length of the description if sometimes small and sometimes very very large.
Now, I have a Image view on the left and description on the right .Please find the below image for reference
.
I want to show the description occupy the entire tableview cell width if the description slides down even after the image view. How can i achieve this ?
最满意答案
我建议你使用自动布局。 您需要为imageView设置高度和宽度约束。 不要为textview / label指定宽度,而应指定它的前导和尾随约束。 为imageview的宽度约束创建一个出口。 如果您没有要在imageview中显示的图像,请添加条件检查以将其设置为0,否则将其设置为常量值。 如果图像视图的宽度变为零,则textview将展开,如果您为宽度约束设置了一个常数值,则该视图会减小。 此外,在你的tableview委托在heightForRow和estimatedHeightForRow返回UITableViewAutomaticDimension 。
I would suggest you use Auto-layout for this. You'll need to set the height and width constraints for your imageView. Don't specify width for your textview/label, instead specify the leading and trailing constraints for the it. Create an outlet for the width constraint of the imageview. If you don't have an image to display in the imageview add a condition check to set it to 0, otherwise set it to the constant value. If the imageview's width becomes zero, the textview will expand and it will decrease if the you set a constant value for the width constraint. Also, in your tableview delegate return UITableViewAutomaticDimension in both heightForRow and estimatedHeightForRow.
更多推荐
发布评论