UITableViewCell 可变高度,具有多个 UILabels 和 IB

发布于 2024-08-20 14:50:22 字数 368 浏览 4 评论 0原文

好吧,我这里遇到的情况让我发疯。我正在使用自定义 UITableViewCell 加载 UITableView。现在这个单元格中有几个 UILabel。

所以顺序是:

Label1 标签2 标签3 Label4

现在Label2 具有固定的高度。 Label1、Label3、Label4需要根据字符串的大小改变其高度。我使用推荐的方法来计算每个标签的高度: - sizeWithFont:c constrainedToSize: lineBreakMode:UILineBreakModeWordWrap

但是标签彼此重叠。不确定如何放置这些标签?

或者有更好的方法来做到这一点吗?

谢谢

Alright so I have a situation here that is making me go crazy. I am loading a UITableView with a custom UITableViewCell. Now this cell has couple of UILabel's in it.

so the order is:

Label1
Label2
Label3
Label4

Now Label2 has a fixed height. Label1, Label3 and Label4 will need to change their height according to the size of string. I am using the recommended way to calculate the height for each label using: - sizeWithFont:c constrainedToSize: lineBreakMode:UILineBreakModeWordWrap

But the label's are overlapping each other. Not sure how to position these labels?

Or is there a better way to do this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

场罚期间 2024-08-27 14:50:22

定位第一个标签,获取其大小,然后根据前一个标签的框架定位每个后续标签。

为方便起见,您可以将此代码放入单独的方法中,调用一次以生成该单元格的高度以在 -tableView:heightForRowAtIndexPath: 委托方法中使用,并为-tableView:cellForRowAtIndexPath: 委托方法。

Position the first label, get its size, and then position each subsequent label by the previous label's frame.

For convenience, you might put this code into a separate method, calling it once to generate that cell's height for use in the -tableView:heightForRowAtIndexPath: delegate method, as well as have those labels set up for the -tableView:cellForRowAtIndexPath: delegate method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文