Frequently asked questions for JSQMessagesViewController.
Contributions are welcome! Please submit a pull request.
Is the library compatible with UITabBarController
and UITabBar
? Yes and no. For the history on this issue, see #179 and #94. This seems to be the best workaround:
- (void)viewDidLoad
{
[super viewDidLoad];
self.edgesForExtendedLayout = UIRectEdgeNone;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.collectionView.collectionViewLayout.springinessEnabled = YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionView.collectionViewLayout.incomingAvatarViewSize = CGSizeZero;
self.collectionView.collectionViewLayout.outgoingAvatarViewSize = CGSizeZero;
}
- (id<JSQMessageAvatarImageDataSource>)collectionView:(JSQMessagesCollectionView *)collectionView avatarImageDataForItemAtIndexPath:(NSIndexPath *)indexPath
{
return nil;
}
There are 2 approaches to this, which one you choose depends on your needs.
- Customize appearance and behavior of existing cells. (Easy)
- Provide your own completely custom cell prototypes. (Hard)
Also see previous issues.
If you only need to make minor changes to the existing cells (colors, data detectors, etc.), then you simply need to override the following method. You have access to all properties on the cell. (docs)
- (UICollectionViewCell *)collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell *)[super collectionView:collectionView cellForItemAtIndexPath:indexPath];
// Customize the shit out of this cell
// See the docs for JSQMessagesCollectionViewCell
return cell;
}
This approach is more involved, but gives you greater flexibility. If you need to add or modify subviews of the cell, use this approach. (docs)
- You need to provide your own cell subclasses, similar to the library's
JSQMessagesCollectionViewCell
,JSQMessagesCollectionViewCellIncoming
,JSQMessagesCollectionViewCellOutgoing
. - On your
JSQMessagesViewController
subclass, set the following properties according to your classes:outgoingCellIdentifier
outgoingMediaCellIdentifier
incomingCellIdentifier
incomingMediaCellIdentifier
- Register your cell classes/nibs with the collection view and the identifiers above
- Override
-collectionView: cellForItemAtIndexPath:
. Do not callsuper
. Since you are providing your own cells, callingsuper
will perform a bunch of unnecessary work. - (Optional) For your model objects, implement
JSQMessageData
or subclassJSQMessage
and extend to your needs.
For more detailed instructions on creating custom cells, see this comment
- (void)viewDidLoad
{
[super viewDidLoad];
// This button will call the `didPressAccessoryButton:` selector on your JSQMessagesViewController subclass
self.inputToolbar.contentView.leftBarButtonItem = /* custom button or nil to remove */
// This button will call the `didPressSendButton:` selector on your JSQMessagesViewController subclass
self.inputToolbar.contentView.rightBarButtonItem = /* custom button or nil to remove */
// Swap buttons, move send button to the LEFT side and the attachment button to the RIGHT
// For RTL language support
self.inputToolbar.contentView.leftBarButtonItem = [JSQMessagesToolbarButtonFactory defaultSendButtonItem];
self.inputToolbar.contentView.rightBarButtonItem = [JSQMessagesToolbarButtonFactory defaultAccessoryButtonItem];
// The library will call the correct selector for each button, based on this value
self.inputToolbar.sendButtonOnRight = NO;
}