[![CI Status](http://img.shields.io/travis/José Lucas/JLChatViewController.svg?style=flat)](https://travis-ci.org/José Lucas/JLChatViewController)
To run the example project, clone the repo, and run pod install
from the Example directory first.
If you want to use this framework you will need at least IOS 8!
JLChatViewController is available through CocoaPods. To install it, simply add the following line to your 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
-If you want to use custom bubbles images I advise you to use images with 32x32 pixels for @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)
-If you want to use default bubbles images
JLChatAppearence.configIncomingMessages(nil, showIncomingSenderImage: true, incomingTextColor: nil)
JLChatAppearence.configOutgoingMessages(nil, showOutgoingSenderImage: true, outgoingTextColor: nil)
-This method is optional, it is normally used when you are using custom bubbles images, but fell free to use it when ever you want.
JLChatAppearence.configAligment(5, vertivalDistBetweenImgBottom_And_BubbleBottom: 10)
-This method is optional, it is normally used when you are using custom bubbles images, but fell free to use it when ever you want.
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)
Use it to open your Chat 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
}
Create a .xib file that have a UIView
and add all necessary views, more details on example project.
Register it on your chat tableView
self.chatTableView.registerNib(UINib(nibName: "nib name", bundle: NSBundle.mainBundle()), forHeaderFooterViewReuseIdentifier: "identifier")
implement the methods of ChatDataSource
that is for custom cells
func jlChatCustomHeaderInSection(section:Int)->UIView?
func jlChatHeightForCustomHeaderInSection(section:Int)->CGFloat
José Lucas, [email protected]
JLChatViewController is available under the MIT license. See the LICENSE file for more info.