要运行示例项目,请克隆仓库,然后首先从 Example 目录中运行 pod install
。
如果您想使用此框架,您需要至少 IOS 8!
JLChatViewController 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "JLChatViewController"
IMPORTANT = These and other improvements made necessary some changes on implementations of delegates, some methods were deprecated , so its important you take a look again on example project to make the right corrections.
- Now you can use your own bubble form images with simple and fast configuration
- Now you can add custom header views for example use your own Date Header View, use one for indicating the number of unread messages
`JLChatLabel` was added to substitute the `JLChatTextView` on `JLTextMessageCell` specially for performance.I advice you to use `JLChatLabel` instead of `JLChatTextView` when possible .
Import it on every file that you will use this framework.
import JLChatViewController
Call this method on AppDelegate for you load the `JLChat.storyboard`, but you can call it where you prefer.
JLBundleController.loadJLChatStoryboard()
Your ViewController that will have the chat must inherit from `JLChatViewController` and implement all these protocols:
`ChatDataSource`,`ChatToolBarDelegate`,`JLChatMessagesMenuDelegate`,`ChatDelegate`.
Find `JLChat.storyboard` open it, choose the ViewController and put your ViewController that inherits from `JLChatViewController` as the class of this one.
You will need some way to know the correctly number of sections(Date sections and/or custom sections), the number of messages by section on your chat.
If you have some doubt about it take a look on Mark `Chat messages by section methods` of MyViewController
Change the parameters values as you prefer
The example project has some ways of customization implemented
- 如果您想使用自定义气泡图像,建议您使用 32x32 像素的图像用于 @1x
JLChatAppearence.configIncomingMessages(WithCustomBubbleImage: UIImage(named: "custom-incomingBubble"), customBubbleInsets: UIEdgeInsets(top: 14, left: 14, bottom: 14, right: 14), bubbleImageMask: UIImage(named: "custom-incomingBubbleMask"), bubbleMaskInsets: UIEdgeInsets(top: 14, left: 14, bottom: 14, right: 14), incomingBubbleColor: nil, showIncomingSenderImage: true, incomingTextColor: nil)
JLChatAppearence.configOutgoingMessages(WithCustomBubbleImage: UIImage(named: "custom-outgoingBubble"), customBubbleInsets: UIEdgeInsets(top: 14, left: 14, bottom: 14, right: 14), bubbleImageMask: UIImage(named: "custom-outgoingBubbleMask"), bubbleMaskInsets: UIEdgeInsets(top: 14, left: 14, bottom: 14, right: 14), outgoingBubbleColor: nil, showOutgoingSenderImage: true, outgoingTextColor: nil)
- 如果您想使用默认的气泡图像
JLChatAppearence.configIncomingMessages(nil, showIncomingSenderImage: true, incomingTextColor: nil)
JLChatAppearence.configOutgoingMessages(nil, showOutgoingSenderImage: true, outgoingTextColor: nil)
-此方法为可选,通常在您使用自定义气泡图像时使用,但您随时可以使用它。
JLChatAppearence.configAligment(5, vertivalDistBetweenImgBottom_And_BubbleBottom: 10)
-此方法为可选,通常在您使用自定义气泡图像时使用,但您随时可以使用它。
JLChatAppearence.configTextAlignmentOnBubble(IncomingMessTextAlig: UIEdgeInsets(top: 8, left: 10, bottom: 13, right: 8), AndOutgoingMessTextAlig: UIEdgeInsets(top: 8, left: 8, bottom: 13, right: 10))
JLChatAppearence.configSenderImage(nil, senderImageCornerRadius: nil, senderImageBackgroundColor: nil, senderImageDefaultImage: nil)
JLChatAppearence.configErrorButton(nil, selectedStateImage: nil)
More information take a look on documentation
public func addNewMessages(quant:Int,changesHandler:()->(),completionHandler:(()->())?)
public func addOldMessages(quant:Int,changesHandler:()->())
public func removeMessageCellAtIndexPath(indexPath:NSIndexPath,relatedMessage:JLMessage!)
public func removeChatSection(section:Int,messagesOfSection:[JLMessage]?)
public func removeMessagesCells(rowsIndexPath:[NSIndexPath]?,AndSections sections:[Int]?,WithRelatedMessages relatedMessages:[JLMessage]?)
public func updateMessageStatusOfCellAtIndexPath(indexPath:NSIndexPath,message:JLMessage)
使用它来打开您的聊天 ViewController
if let vc = JLBundleController.instantiateJLChatVC() as? /*Name of your ViewController that inherits from JLChatViewController*/{
vc.view.frame = self.view.frame
let chatSegue = UIStoryboardSegue(identifier: "identifier name", source: self, destination: vc, performHandler: { () -> Void in
self.navigationController?.pushViewController(vc, animated: true)
})
self.prepareForSegue(chatSegue, sender: nil)
chatSegue.perform()
}
Create a class that inherits from `JLChatMessageCell` and implement all necessary methods , more details on example project
Create a .xib file that have a `UITableViewCell` and add all necessary views, more details on example project.
Attention! there are some constraints of errorButton and senderImageView that must have to exist, for everything works well , more details take a look on custom cell of the example project.
Register them on your chat tableView
self.chatTableView.registerNib(UINib(nibName: "nib name", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "identifier")
implement the method of `ChatDataSource` that is for custom cells
func chat(chat: JLChatTableView, customMessageCellForRowAtIndexPath indexPath: NSIndexPath) -> JLChatMessageCell {
...
var cell:JLChatMessageCell!
if message.senderID == self.chatTableView.myID{
cell = self.chatTableView.dequeueReusableCellWithIdentifier("your identifier for outgoing message") as! CellName
}
else{
cell = self.chatTableView.dequeueReusableCellWithIdentifier("your identifier for incoming message") as! CellName
}
return cell
}
创建一个包含 UIView
的 .xib 文件并添加所有必要的视图,更多详情请参考示例项目。
在您的聊天 tableView 中注册它
self.chatTableView.registerNib(UINib(nibName: "nib name", bundle: NSBundle.mainBundle()), forHeaderFooterViewReuseIdentifier: "identifier")
实现自定义单元格的 ChatDataSource
方法
func jlChatCustomHeaderInSection(section:Int)->UIView?
func jlChatHeightForCustomHeaderInSection(section:Int)->CGFloat
José Lucas, [email protected]
JLChatViewController 基于 MIT 许可证可用。有关更多信息,请参阅 LICENSE 文件。