简体   繁体   English

带有VFL的uitableviewcell动态标签宽度

[英]uitableviewcell dynamic label width with VFL

I need to fit a label and an image in a table view cell in such a way that the image should be placed immediately next to the label but within the cell visibility. 我需要在表格视图单元格中放置标签和图像,以使图像应紧邻标签放置但在单元格可见性之内。 ie., they should look like below, 即,它们应该如下图所示

  1. When the text is smaller or within a line, then the image could be immediate next to the label. 当文本较小或在一行中时,图像可能会紧靠标签旁边。 Eg - 例如-
Smaller text (image)
  1. When the text goes beyond a line, then image could be at the edge of the cell because the label length had already been extended to the length. 当文本超出一行时,图像可能位于单元格的边缘,因为标签长度已经扩展到该长度。 Eg - 例如-
Multiline text multi-line text multi-line
text multi-line text multi-line text multi  (image) 
multi-line text multi-line text

I am trying to achieve this using VFL and no storyboard or nib. 我正在尝试使用VFL来实现此目的,而不使用情节提要或笔尖。

What I tried out : 我尝试了什么:

1. "H:|-[label]-[image(==20)]-|"  , "V:|-[label]-|"

This makes the image to always attached to the edge thus the case 1 fails which needs the image near the label. 这使得图像始终附着在边缘上,因此外壳1出现故障,需要图像靠近标签。 Eg - 例如-

case 1 : 情况1 :

Smaller text                                (image)    (not ok)

case 2 : 情况2:

Multiline text multi-line text multi-line
text multi-line text multi-line text multi  (image)    (ok)
multi-line text multi-line text
2. "H:|-[label]-[image(==20)]" , "V:|-[label]-|"

This makes the image near the text thus okay for case 1 whereas that fails for case 2 which does not wrap the text to multiple lines then and the text is extending beyond the cell width. 这样,情况1的文本附近的图像就可以了,而情况2的图像失败了,情况2没有将文本包装到多行,并且文本超出了单元格的宽度。 Eg - 例如-

case 1 : 情况1 :

Smaller text (image)             (ok)

case 2 : 情况2:

Multiline text multi-line text multi-line text multi...    
(not ok - text not wrapped to multiple lines, remaining text and image hidden)

How to resolve this? 如何解决呢? Setting priorities to some constraints would help ? 将优先级设置为某些限制会有所帮助吗?

I don't have much experience with VFL but , I know Autolayout so I can give you Idea how to resolve 我在VFL上没有太多经验,但是,我知道自动Autolayout因此我可以为您提供解决方法的想法

I have seen your both tries 我看过你的两次尝试

1. "H:|-[label]-[image(==20)]-|"  , "V:|-[label]-|"
2. "H:|-[label]-[image(==20)]" , "V:|-[label]-|"

In first try you have fixed image on trailing 在第一次尝试中,您在尾随上有固定的图像

on second try you have fixed image with label 在第二次尝试中,您有带有标签的固定图像

What would be combine solution ? 什么是联合解决方案?

Your clear requirement says that you need your image attached with label trailing also take care about tailing to superview 您明确的要求是,您需要在图像上附加标签尾随,也要注意尾随才能观看

So clear solution for that problem is 因此,解决该问题的明确方法是

you have to give your imageView Trailing may be this code [image(==20)]-| 您必须提供imageView尾随可能是此代码[image(==20)]-| should be changed with Greater than or equal to relation with 0 Constant 应更改为大于或等于 0常量的关系

it will tells autolayout engine to keep Min 0 Distance from trailing of superview 它将告诉自动布局引擎将最小0距离与Superview的尾部保持距离

Sorry I couldn't give you exact code as I don't have much experience with VFL 抱歉,我无法给您确切的代码,因为我对VFL没有太多经验

Hope it will help to you 希望对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM