我在尝试创建一个简单的信使时遇到了这样的问题。这是我来的:
-
class ChatBubleUIView
该类负责创建带有标签的气泡视图。它工作正常,根据标签高度计算视图高度 -
在我的单元格中,我创建了一个内容视图。在单元格类中,我将添加新的
ChatBubleUIView
实例作为内容视图的子视图。 -
问题是,内容无法扩展到我的
ChatBubleInstance
大小。class ChatMessageTableViewCell: UITableViewCell, MessageCellConfiguration { var message: Message? override func awakeFromNib() { super.awakeFromNib() } func configureCell() { let chatBubleView = ChatBubleUIView(message: message!) self.addSubview(chatBubleView) } }
-
在我的表中查看委托
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "messageCell") as! ChatMessageTableViewCell let data = currentUser.mesaageHistory[indexPath.row] cell.message = data cell.configureCell() return cell }
-
我还为我的表设置了估计的行高视图
messageTableView.rowHeight = UITableViewAutomaticDimension messageTableView.estimatedRowHeight = 44
我应该怎么做才能设置为我的表视图行高聊天视图BubleUIView 实例高度。以前,我使用老式方法解决了这个问题,以编程方式确定chatViewBubleUIView实例高度,然后实现heightForRowAtIndexPath
。但我想用AutoLayoaut来做到这一点。
设置标签的四个约束,例如top,bottom,leading,trailing
标签的高度数应0
。 然后它会根据内容自动增加其高度。如果您在任何视图中使用此标签,则视图的约束应与我上面提到的标签相同!