A messages UI for iPhone and iPad.
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!)
This is based on work by @soffes SSMessagingViewController. I took Soffes' code base and developed this to use in Hemoglobe for private messages between users. The features section lists the most notable improvements from SSMessagingViewController.
- Up-to-date for iOS 6.0 and ARC
- Storyboards support (if that's how you roll)
- Universal for iPhone and iPad
- Allows arbitrary message (and bubble) sizes
- Timestamp options
- Swipe/pull down to hide keyboard
- Dynamically resizes input text view as you type
- Smooth hiding/showing keyboard animations with
NSNotification
- Automatically enables/disables send button if text view is empty or not
- Smooth send animations
- Send/Receive sound effects
- Blue or green outgoing message bubble color
From CocoaPods
pod 'JSMessagesViewController'
- Drag the
JSMessagesTableViewController/
folder to your project. - Add the
AudioToolbox.framework
to your project, if you want to use the sound effects - Subclass
JSMessagesViewController
-
Override the following methods:
-
- (JSBubbleMessageStyle)messageStyleForRowAtIndexPath:(NSIndexPath *)indexPath
- The style of the bubble for this row, options are:
JSBubbleMessageStyleIncoming
JSBubbleMessageStyleOutgoing
JSBubbleMessageStyleOutgoingGreen
- The style of the bubble for this row, options are:
-
- (NSString *)textForRowAtIndexPath:(NSIndexPath *)indexPath
- The text to be displayed for this row
-
- (NSDate *)timestampForRowAtIndexPath:(NSIndexPath *)indexPath
- The timestamp to be displayed above this message bubble
-
- (void)sendPressed:(UIButton *)sender withText:(NSString *)text
- Hook into your own backend here
- Call
[self finishSend]
at the end of this method to animate and reset the text input view - Optionally play sound effects:
[JSMessageSoundEffect playMessageSentSound]
or[JSMessageSoundEffect playMessageReceivedSound]
-
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- The API table view data source method that you should be familiar with
-
Set the
timestampPolicy
property in- (void)viewDidLoad
, options are:JSMessagesViewTimestampPolicyAll
JSMessagesViewTimestampPolicyAlternating
JSMessagesViewTimestampPolicyEveryThree
JSMessagesViewTimestampPolicyEveryFive
JSMessagesViewTimestampPolicyCustom
-
NOTE if using
JSMessagesViewTimestampPolicyCustom
YOU MUST OVERRIDE- (BOOL)shouldHaveTimestampForRowAtIndexPath:(NSIndexPath *)indexPath
- See the default implementation of this method for details
-
-
Call
setBackgroundColor:
to set table view background color
- Remember, you must subclass
JSMessagesViewController
- You may present view programmatically, or use Storyboards
- Your
JSMessagesViewController
subclass must be presented in aUINavigationController
MessagesDemo.xcodeproj
for example of programmatic presentationMessagesDemoStoryboards/MessagesDemoSB.xcodeproj
for example of use with Storyboards
- Landscape mode
- Allow text input view to resize up to navigation bar (instead of only 5 lines)
- Display "To: " search field for new messages
- Option for user avatar to display next to bubbles
- "Send" images or video
You are free to use this as you please. No attribution necessary.
If you use this, please tell me about it!
MIT License 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.