如何从左到右显示标签中的文本,取决于是否存在另一个UI元素(How to show the text in label from left to right depending on whther o

编程入门 行业动态 更新时间:2024-10-25 09:25:49
如何从左到右显示标签中的文本,取决于是否存在另一个UI元素(How to show the text in label from left to right depending on whther or not there is another UI Element present)

我试图在我的表格视图单元格中显示一些内容。 我在左边有一张图片,我必须在右侧显示一些文字(说明)。 一切都是动态的。 所以描述的长度有时很小,有时非常大。

现在,我在左侧有一个图像视图,在右侧有说明。请查找下面的图像以供参考

如果描述在图像视图之后滑落,我想要显示描述占据整个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.

更多推荐

本文发布于:2023-08-04 14:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417489.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   文本   标签   show   左到右

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!