0

我一直在使用 MessageKit 为我的应用程序提供实时聊天功能。我遇到的问题之一是长消息在屏幕上看起来很奇怪,因为气泡的宽度似乎没有受到限制。我想找到一种方法来设置聊天气泡的最大宽度,以便它们的格式更像原生图像应用程序上的文本对话。

目前我的消息看起来像这样,但我希望下面的消息不那么宽和更高:在此处输入图像描述

4

2 回答 2

1

您可以分别调整传入/传出消息的右/左填充。

默认填充是:

public var incomingMessagePadding = UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 30)
public var outgoingMessagePadding = UIEdgeInsets(top: 0, left: 30, bottom: 0, right: 4)

您可以在消息视图控制器中的布局对象上设置填充,如下所示:

let layout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout
layout?.setMessageIncomingMessagePadding(UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 50))
layout?.setMessageOutgoingMessagePadding(UIEdgeInsets(top: 0, left: 60, bottom: 0, right: 4))

您可以在 MessageKit 示例项目中的 AdvancedExampleViewController 中查看更多布局更改示例。

于 2020-06-17T18:18:22.797 回答
0

您正在使用的库似乎已经设置了宽度,但是在我的聊天中(这是自定义的)我有a greater than or equal than 0 width constraint一个a less than or equal than MAX_WIDTH constraintaleading constraint = 0和一个'尾随约束 = 0',最后两个我摆脱了leadingortrailing取决于它是否是消息的发送者或接收者。

于 2020-06-17T05:36:49.643 回答