jessesquires / JSQMessagesViewController

An elegant messages UI library for iOS

Home Page:https://www.jessesquires.com/blog/officially-deprecating-jsqmessagesviewcontroller/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Message Bubbles

chashmeetsingh opened this issue · comments

I am trying to create custom message bubbles but I am unable to do so. Please redirect to some examples for the same.

Custom bubbles as in:

  • Showing GIFs
  • Map View
  • Pie charts
  • Tables
  • many more...

What do you mean custom message bubbles? Right now bubbles are resizable images stored in the assets folder in here: https://github.com/jessesquires/JSQMessagesViewController/tree/develop/JSQMessagesViewController/Assets/JSQMessagesAssets.bundle/Images

To customize you have to either add your own images and then reference using BubbleImageFactory or write more code to customize the picture

Customizable as in I want to use the resizing and the bubble view and the content inside I can customize that. So it will not be limited to images but also add like text + images, text + mapview.

@chashmeetsingh for this You have to create your own CustomMediaItem class inherited from JSQMediaItem. And override the super class methods to customize your view.
`
class CustomMediaItem: JSQMediaItem
{

override init(maskAsOutgoing: Bool)
{
    super.init(maskAsOutgoing: maskAsOutgoing)
}

required init?(coder aDecoder: NSCoder)
{
    fatalError("init(coder:) has not been implemented")
}

override func clearCachedMediaViews()
{
    super.clearCachedMediaViews()
}

override func mediaView() -> UIView?
{        
    //your own custom view 
    return your custom view
}

override func mediaViewDisplaySize() -> CGSize
{
    //define the size of the view based on the content you have
    return CGSize(width: 320, height: 320)
}

override func mediaHash() -> UInt
{  
     //this is very important function to implement other wise your bubble disappears while scrolling 
     if you have not implemented properly
    return super.mediaHash() ^ UInt(abs(self.text.hash))
}

}`