Skip to content

sternhenri/MessagesTableViewController

 
 

Repository files navigation

JSMessagesViewController Build Status

A messages UI for iPhone and iPad.

Messages Screenshot 1     Messages Screenshot 2

This messages tableview controller is very similar to the one in the iOS Messages app. Note, this is only a messaging UI, not a messaging app. This is intended to be used in an existing app where you have (or are developing) a messaging system and need a user interface for it.

See more screenshots in the Screenshots/ directory. (Surprise!)

Update!

####Version 3.0.0 just released with a brand new API! iOS 7 support + documentation coming soon!

Features

  • Highly customizable
  • Arbitrary message sizes
  • Copy & paste messages
  • Support for group messages
  • Data detectors (recognizes phone numbers, links, dates, etc)
  • Timestamps
  • Avatars
  • Subtitles
  • Lots of bubble styles, or use your own!
  • Swipe down to hide keyboard
  • Dynamically resizes input text view as you type
  • Smooth animations
  • Automatically enables/disables send button (if text view is empty or not)
  • Send/Receive sound effects
  • Storyboards support (if that's how you roll)
  • Universal

Requirements

  • iOS 6.0+
  • ARC

Installation

pod 'JSMessagesViewController'

From source

  • Drag the JSMessagesViewController/ folder to your project.
  • Add the AudioToolbox.framework to your project, if you want to use the sound effects

How To Use

###Subclass JSMessagesViewController

  • In - (void)viewDidLoad
    • Set your view controller as the delegate and datasource
    • Set your view controller title

###Implement the JSMessagesViewDelegate protocol

- (void)didSendText:(NSString *)text;
  • Hook into your own backend here
  • Call finishSend at the end of this method to animate and reset the text input view
  • Call scrollToBottomAnimated: to scroll to newly sent message
  • Optionally play sound effects
    • For outgoing messages [JSMessageSoundEffect playMessageSentSound]
    • For incoming messages [JSMessageSoundEffect playMessageReceivedSound]
- (JSBubbleMessageType)messageTypeForRowAtIndexPath:(NSIndexPath *)indexPath;
  • The type of bubble for this row, options are:
    • JSBubbleMessageTypeIncoming
    • JSBubbleMessageTypeOutgoing
- (UIImageView *)bubbleImageViewWithType:(JSBubbleMessageType)type
                       forRowAtIndexPath:(NSIndexPath *)indexPath;
- (JSMessagesViewTimestampPolicy)timestampPolicy
  • How/when to display timestamps for messages:
    • JSMessagesViewTimestampPolicyAll
    • JSMessagesViewTimestampPolicyAlternating
    • JSMessagesViewTimestampPolicyEveryThree
    • JSMessagesViewTimestampPolicyEveryFive
    • JSMessagesViewTimestampPolicyCustom
- (JSMessagesViewAvatarPolicy)avatarPolicy
  • How/when to display avatars:
    • JSMessagesViewAvatarPolicyAll
    • JSMessagesViewAvatarPolicyIncomingOnly
    • JSMessagesViewAvatarPolicyOutgoingOnly
    • JSMessagesViewAvatarPolicyNone
- (JSMessagesViewSubtitlePolicy)subtitlePolicy;
  • How/when to display subtitles:
    • JSMessagesViewSubtitlePolicyAll
    • JSMessagesViewSubtitlePolicyIncomingOnly
    • JSMessagesViewSubtitlePolicyOutgoingOnly
    • JSMessagesViewSubtitlePolicyNone
- (BOOL)hasTimestampForRowAtIndexPath:(NSIndexPath *)indexPath
  • Optional Returns if this row should display a timestamp or not
  • Required if using JSMessagesViewTimestampPolicyCustom
- (BOOL)shouldPreventScrollToBottomWhileUserScrolling;
  • Optional Return YES if you would like to prevent the tableview from being scrolled to the bottom while the user is scrolling the tableview manually. The method scrollToRowAtIndexPath:indexPath:atScrollPosition:animated: can also be used to implement scrolling functionality that respects this setting.
- (UIButton *)sendButtonForInputView;
  • Optional Return a custom send button, the frame is set for you.

###Implement the JSMessagesViewDataSource protocol

- (NSString *)textForRowAtIndexPath:(NSIndexPath *)indexPath
  • The text to be displayed for this row
- (NSDate *)timestampForRowAtIndexPath:(NSIndexPath *)indexPath
  • The timestamp to be displayed above this row
- (UIImageView *)avatarImageViewForRowAtIndexPath:(NSIndexPath*)indexPath
  • The avatar image view to be displayed this row
- (NSString *)subtitleForRowAtIndexPath:(NSIndexPath*)indexPath
  • The subtitle text to be displayed below this row

###Implement the table view data source method

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

###Customize

  • For custom background color, use - (void)setBackgroundColor:(UIColor *)color

Notes

  • You may present view programmatically, or use Storyboards
  • Your JSMessagesViewController subclass must be presented in a UINavigationController
  • Demo project included: MessagesDemo.xcodeproj

About

This project was originally based on work by @soffes SSMessagingViewController.

I developed this to use in Hemoglobe for private messages between users.

Square message bubbles designed by @michaelschultz.

Apps Using This Control

Hemoglobe

FourChat

Libraries for developers

Contact me to have your app listed here.

Related Projects

SSMessagingViewController

AcaniChat

UIBubbleTableView

You are free to use this as you please. No attribution necessary. However, a link back to Hexed Bits or here would be appreciated. If you use this, please tell me about it!

Copyright © 2013 Jesse Squires

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Packages

No packages published

Languages

  • Objective-C 99.5%
  • Ruby 0.5%