gpt4 book ai didi

ios - 根据行高在 UITableViewCell 中移动 UIImage

转载 作者:行者123 更新时间:2023-11-29 02:41:32 25 4
gpt4 key购买 nike

我有一个虚线图像,它应该几乎位于我的每个 UITableViewCell 的底部。在 nib 文件中,我将此行置于 40 像素的 y 位置,其中单元格高度为 44 像素。如果文本需要比这更多的垂直空间,我需要将该行向下移动以与额外的行高相对应。

我能够很容易地计算出行高,但我似乎无法重新定位图像。我在 UITableViewCell 的子类中有以下代码:

- (void) layoutSubviews {
[super layoutSubviews];

NSLog(@"before layout adjustment: %f", _imageDashedLine.frame.origin.y);

CGRect lineFrame = _imageDashedLine.frame;
lineFrame.origin.y += self.frame.size.height - 44.0f;
[_imageDashedLine setFrame:lineFrame];

NSLog(@"after layout adjustment: %f", _imageDashedLine.frame.origin.y);
}

这里是一些输出结果:

before layout adjustment: 0.000000
after layout adjustment: 0.000000
before layout adjustment: 0.000000
after layout adjustment: 16.000000
before layout adjustment: 0.000000
after layout adjustment: 16.000000
before layout adjustment: 0.000000
after layout adjustment: 0.000000
before layout adjustment: 0.000000
after layout adjustment: 16.000000

您可以看到,在某些情况下,我不需要重新定位图像,但在其他情况下我需要这样做。我能够确定将图像向下移动所需的垂直距离。但是,在任何情况下都不会在绘制时重新定位图像。它只是停留在它开始的地方,这搞砸了我的手机显示。

谁能看出我做错了什么?谢谢!

最佳答案

如果您不使用自动布局,请在 UITabelViewCell 的 nib 类中的 UIImageVIew 上,提供 leftbottom 来自尺寸检查选项卡中自动调整尺寸框的位置约束。现在,图像在任何情况下都将保留在底部。

如果您使用自动布局,请提供适当的约束,使图像保持在底部,而不受单元格高度变化的影响。

关于ios - 根据行高在 UITableViewCell 中移动 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25717172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com