![](/img/trans.png)
[英]How to increase Label Height(Depend on Text) in Tableview cell when used Autolayout Table view?
[英]Cell height is not increasing depend on the label text in tableview swift
我需要更改单元格高度取决于消息 label 文本
对于消息 label 我已经给出了限制
trailing = leading = top = 10, height => 30 (greater then or equal to height)
和行数 = 0
现在 label 正在增加但单元格没有增加,为什么?
o/p
代码:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return msgArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MessageDetailsTableViewCell", for: indexPath) as! MessageDetailsTableViewCell
self.tableView.separatorStyle = .none
cell.msgLabel.text = msgArray[indexPath.row]
cell.nameLabel.text = nameArray[indexPath.row]
cell.timeLabel.text = timeArray[indexPath.row]
cell.picImageview.image = UIImage(named: "icon12")
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100//UITableView.automaticDimension
}
如果我给heightForRowAt = UITableView.automaticDimension
那么什么都没有,如果我将其高度固定为 100 那么单元格不会增加,为什么? 请帮忙
您可以通过两个步骤简单地完成 go:
1. heightForRowAt 方法:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
2.UILabel 属性
yourLabel.numberOfLines = 0 // or you can set numberOfLines from storyBoard.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.