编辑MessageKit布局

时间:2020-01-30 06:31:24

标签: ios swift user-interface layout messagekit

这是我第一次使用MessageKit。我正在尝试自定义视图,但找不到任何有用的信息,例如设置插图和更改背景颜色。

My current layout

我想从标题栏下面开始查看,并更改背景颜色和消息的背景颜色。

func backgroundColor(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UIColor {
        return isFromCurrentSender(message: message) ? UIColor.myGold : UIColor.headingGold
    }

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

您必须为contentInset中的messagesCollectionView设置viewDidLayoutSubviews()才能在标题栏下方开始查看

self.messagesCollectionView.contentInset = UIEdgeInsets(top: title bar height, left: 0, bottom: 70, right: 0)

要设置消息的背景色,您必须使用MessagesDisplayDelegate方法和委托,dataSource应该与视图控制器连接

func backgroundColor(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UIColor {
        return isFromCurrentSender(message: message) ? UIColor.blue : UIColor.gray
    }

要进行更多自定义,您必须查看MessageKit回购中的MessageKit示例

相关问题