我正在使用MessageKit库实现一个简单的聊天屏幕。正如您在第一个屏幕截图中看到的那样,一切听起来都很正常,但我被要求做的是将所有线程对齐到左侧(第二个屏幕截图)。我试图找到一种方法来改变线程对齐,但我做不到。如果有人可以帮助我找到方法,我将不胜感激。
这是我的代码的一部分:
extension ConversationDataSource: MessagesDisplayDelegate {
// MARK: - MessagesDisplayDelegate implementation
func messageStyle(for message: MessageType, at indexPath: IndexPath,
in messagesCollectionView: MessagesCollectionView) -> MessageStyle {
return .bubbleTail(isFromCurrentSender(message: message) ? .topRight : .topLeft, .curved)
}
func backgroundColor(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UIColor {
return isFromCurrentSender(message: message) ? .aeroBlue : .white
}
func textColor(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UIColor {
return .black
}
func enabledDetectors(for message: MessageType, at indexPath: IndexPath,
in messagesCollectionView: MessagesCollectionView) -> [DetectorType] {
return [.url, .address, .phoneNumber, .date]
}
func detectorAttributes(for detector: DetectorType, and message: MessageType,
at indexPath: IndexPath) -> [NSAttributedString.Key: Any] {
// Project doesn't build with Xcode 10 without implementing this explicitly
return [NSAttributedString.Key.foregroundColor: UIColor.darkText,
NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue,
NSAttributedString.Key.underlineColor: UIColor.darkText]
}
}
PS:请不要介意设计,对齐是现在的问题