简体   繁体   English

自定义 UITableViewCell label 的奇怪行为

[英]Strange behavior of custom UITableViewCell label

I don't know why, but my label behaves strangely.我不知道为什么,但我的 label 行为异常。 You can check screenshots bellow.您可以查看下面的屏幕截图。 Image should fill stackView.图像应填充 stackView。

Screenshots截图

Since you really ought to share a bit more, I can only try to answer based on what's available.既然你真的应该分享更多,我只能尝试根据可用的内容来回答。

The problem is most likely due to the fact that the StackView that surrounds the label and image does not have a width or height constraint of any sort and/or the imageView has a very low content compression resistance property.问题很可能是由于围绕 label 和图像的 StackView 没有任何类型的宽度或高度约束和/或 imageView 具有非常低的内容压缩阻力属性。

Because StackViews calculate their size based on their child views, it will try to find the best fit.因为 StackViews 会根据它们的子视图计算它们的大小,所以它会尝试找到最合适的。 If the label has a normal compression resistance but the imageView has its resistance set to low, the stackView will simply calculate its frame based on the label alone.如果 label 具有正常的抗压性,但 imageView 的抗性设置为低,则 stackView 将仅根据 label 简单地计算其帧。

So to fix it check the compression resistance of those objects or define contraints for the surrounding stackView to match its parents width.因此,要修复它,请检查这些对象的抗压性或为周围的 stackView 定义约束以匹配其父级宽度。

Firstly.. What is it that you are trying to achieve?首先.. 你想要达到什么目的? Image and Text one beside the other, or one below the other?图像和文本一个并排,还是一个在另一个之下? You might want to check for the stackview direction property您可能需要检查 stackview 方向属性

Secondly if you want that your image size remains constant, you will have to give your image view some fixed width constraint, and stackview will respect the size of the imageview.其次,如果您希望图像大小保持不变,则必须为图像视图提供一些固定宽度约束,并且 stackview 将尊重 imageview 的大小。 Or if you want that the image takes the entire width of the screen, you can basically pin the stackview to the edges of the screen, after you have put in the imageview inside of the stackview.或者,如果您希望图像占据屏幕的整个宽度,则基本上可以在将 imageview 放入 stackview 之后将 stackview 固定到屏幕边缘。

Hope that makes sense.希望这是有道理的。 Comment back if you need more help:)如果您需要更多帮助,请回复评论:)

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

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