gpt4 book ai didi

ios - JSQMessagesViewController 消息气泡对齐不规则

转载 作者:可可西里 更新时间:2023-11-01 00:23:45 26 4
gpt4 key购买 nike

我正在使用 JSQMessagesViewController 开发一个应用程序。但是在 collectionView 中存在消息气泡对齐不规则顺序的问题。

这是截图

enter image description here

代码如下:

import UIKit

class mDetailContainerViewController: JSQMessagesViewController, JSQMessagesCollectionViewDelegateFlowLayout{


var userName = ""
var messages = [JSQMessage]()
let incomingBubble = JSQMessagesBubbleImageFactory().incomingMessagesBubbleImageWithColor(UIColor.lightGrayColor())
let outgoingBubble = JSQMessagesBubbleImageFactory().incomingMessagesBubbleImageWithColor(UIColor.greenColor())

override func viewDidLoad() {
super.viewDidLoad()

self.userName = "iPhone"

for i in 1...10{

var sender = (i%2 == 0) ? "Syncano" : self.userName
var message = JSQMessage(senderId: sender, displayName: sender, text: "Text")
self.messages += [message]


}

self.collectionView.reloadData()
self.senderDisplayName = self.userName
self.senderId = self.userName
// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func collectionView(collectionView: JSQMessagesCollectionView!, messageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageData! {
var data = self.messages[indexPath.row]
return data
}

override func collectionView(collectionView: JSQMessagesCollectionView!, messageBubbleImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageBubbleImageDataSource! {
var data = self.messages[indexPath.row]
if (data.senderId == self.senderId){

return self.outgoingBubble

}else{

return self.incomingBubble

}
}

override func collectionView(collectionView: JSQMessagesCollectionView!, avatarImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageAvatarImageDataSource! {
return nil
}

override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.messages.count
}

override func didPressSendButton(button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: NSDate!) {
var message = JSQMessage(senderId: senderId, displayName: senderDisplayName, text: text)
messages += [message]
self.finishSendingMessage()
}

override func didPressAccessoryButton(sender: UIButton!) {

}

我在互联网上搜索了一下解决方案,但所有的说明都很复杂。我什么也没弄清楚。此外,我不确定我是否找到了解决方案。如果有人简单地解释解决方案,我会很高兴。

注意:JSQMessagesViewController 显示在容器 View 中。

最后,如何使用本地化更改发送按钮标题和文本字段占位符。

谢谢。

最佳答案

我不熟悉这个SDK,但我认为这是因为这两行

let incomingBubble = JSQMessagesBubbleImageFactory().incomingMessagesBubbleImageWithColor(UIColor.lightGrayColor())
let outgoingBubble = JSQMessagesBubbleImageFactory().incomingMessagesBubbleImageWithColor(UIColor.greenColor())

incomingMessagesBubbleImageWithColor。将 outgoingBubble 设置为 JSQMessagesBubbleImageFactory().outgoingMessagesBubbleImageWithColor(如果存在)

而且我以前从未使用过这个消息类,但我相信您与绿色文本的对齐问题可能会通过类似...的方式解决

outgoingBubble.textLabel.textAlignment = NSTextAlignment.Center

关于ios - JSQMessagesViewController 消息气泡对齐不规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31810582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com