UITableViewCell 可变高度,具有多个 UILabels 和 IB
好吧,我这里遇到的情况让我发疯。我正在使用自定义 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
定位第一个标签,获取其大小,然后根据前一个标签的框架定位每个后续标签。
为方便起见,您可以将此代码放入单独的方法中,调用一次以生成该单元格的高度以在
-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.