简体   繁体   English

如何将 messageBottomLabel 放入消息气泡中?

[英]How to put messageBottomLabel inside of message bubble?

I am using messageKit.我正在使用 messageKit。 I want to add time when the message was sent inside of messageBottomLabel.我想添加消息在 messageBottomLabel 中发送的时间。 However visually it is outside of message bubble.但是在视觉上它在消息气泡之外。

在此处输入图像描述<\/a>

But I want it to be inside of the bubble, like this:但我希望它位于气泡内,如下所示:

在此处输入图像描述<\/a>

How can I do it?我该怎么做?

"

  1. You have to hide the default bottom label.您必须隐藏默认的底部标签。 (MessagesLayoutDelegate) (MessagesLayoutDelegate)
  2. Make a custom cell for each kind of message you want to change.为您要更改的每种消息创建一个自定义单元格。
  3. Register cell注册单元格
  4. Change the function below to use the custom cell.更改下面的函数以使用自定义单元格。

func customCell(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UICollectionViewCell func customCell(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UICollectionViewCell

  1. Add a label to the content view of the cell.将标签添加到单元格的内容视图。
  2. At cell configuration在单元配置

func configure(with message: MessageType, at indexPath: IndexPath, and messagesCollectionView: MessagesCollectionView) func 配置(带有消息:MessageType,在 indexPath:IndexPath 和 messagesCollectionView:MessagesCollectionView)

set label text like this:像这样设置标签文本:

 if let dataSource = messagesCollectionView.messagesDataSource { captionLabel.text = dataSource.messageBottomLabelAttributedText(for: message, at: indexPath) } else { fatalError("Datasource is null!") }
  1. Then, you have to calculate the height of the cell at然后,您必须计算单元格的高度

override func messageContainerSize(for message: MessageType) -> CGSize覆盖 func messageContainerSize(for message: MessageType) -> CGSize

看看这篇文章: 创建聊天气泡<\/a>

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM