【问题标题】:How to put messageBottomLabel inside of message bubble?如何将 messageBottomLabel 放在消息气泡内?
【发布时间】:2021-06-27 07:08:30
【问题描述】:

我正在使用 messageKit。我想添加消息在 messageBottomLabel 中发送的时间。但是在视觉上它在消息气泡之外。

但我希望它在气泡内,像这样:

我该怎么做?

【问题讨论】:

    标签: swift messagekit


    【解决方案1】:
    1. 您必须隐藏默认的底部标签。 (MessagesLayoutDelegate)
    2. 为您要更改的每种消息创建一个自定义单元格。
    3. 注册单元格
    4. 更改下面的函数以使用自定义单元格。

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

    1. 为单元格的内容视图添加标签。
    2. 在单元配置中

    func 配置(带有消息:MessageType,在 indexPath: IndexPath 和 messagesCollectionView:MessagesCollectionView)

    这样设置标签文本:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-03
      • 1970-01-01
      • 2020-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多