Skip to content

s-faychatelard/JSQMessagesViewController-Swift

Repository files navigation

JSQMessagesViewController banner

Screenshot0    Screenshot1   

Screenshot2    Screenshot3

Features

This is a complete rewrite of the awesome project JSQMessagesViewController in Swift. See the website for the list of Objectice-C features which should be include in the Swift version of course.

Dependencies

Getting Started

@import JSQMessagesViewController;
@import JSQMessagesViewController
  • Demo Project

    • There's a demo project named: JSQMessagesViewControllerTest.
  • Message Model

    • Your message model objects should conform to the JSQMessageData protocol.
    • However, you may use the provided JSQMessage class.
  • Media Attachment Model

    • Your media attachment model objects should conform to the JSQMessageMediaData protocol.
    • However, you may use the provided classes: JSQPhotoMediaItem, JSQLocationMediaItem, JSQVideoMediaItem.
    • Creating your own custom media items is easy! Simply follow the pattern used by the built-in media types.
    • Also see JSQMessagesMediaViewBubbleImageMasker for masking your custom media views as message bubbles.
  • Avatar Model

    • Your avatar model objects should conform to the JSQMessageAvatarImageDataSource protocol.
    • However, you may use the provided JSQMessagesAvatarImage class.
    • Also see JSQMessagesAvatarImageFactory for easily generating custom avatars.
  • Message Bubble Model

    • Your message bubble model objects should conform to the JSQMessageBubbleImageDataSource protocol.
    • However, you may use the provided JSQMessagesBubbleImage class.
    • Also see JSQMessagesBubbleImageFactory and UIImage+JSQMessages.h for easily generating custom bubbles.
  • View Controller

    • Subclass JSQMessagesViewController.
    • Implement the required methods in the JSQMessagesCollectionViewDataSource protocol.
    • Implement the required methods in the JSQMessagesCollectionViewDelegateFlowLayout protocol.
    • Set your senderId and senderDisplayName. These properties correspond to the methods found in JSQMessageData and determine which messages are incoming or outgoing.
  • Customizing

    • You can use the demo project as a guide.

Quick Tips

Springy bubbles? (Not yet functional)
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.collectionView.collectionViewLayout.springinessEnabled = YES;
}
func viewDidAppear(animated: Bool) {

    super.viewDidAppear(animated)
    
    self.collectionView.collectionViewLayout.springinessEnabled = YES
}
Remove avatars?
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.collectionView.collectionViewLayout.incomingAvatarViewSize = CGSizeZero;
    self.collectionView.collectionViewLayout.outgoingAvatarViewSize = CGSizeZero;
}

- (id<JSQMessageAvatarImageDataSource>)collectionView:(JSQMessagesCollectionView *)collectionView avatarImageDataForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return nil;
}
Customize your cells?
- (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;
}
Customize your toolbar buttons?
- (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;
}

Documentation

Read the fucking docs, available here via @CocoaDocs.

Contribute

Please follow these fucking sweet contribution guidelines.

Credits

Created and maintained by @Sylvain Fay-Châtelard from the awesome JSQMessagesViewController project.

About

This is a rewrite in Swift for further project.

License

JSQMessagesViewController is released under an MIT License. See LICENSE for details.

Copyright © 2013-present, Jesse Squires, Sylvain Fay-Châtelard.

Please provide attribution, it is greatly appreciated.

About

JSQMessagesViewController but in Swift

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published