AMBubbleTableViewController 0.5.4

AMBubbleTableViewController 0.5.4

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2015年1月

Andrea Mazzini 维护。



Build Status

这是一个模仿聊天泡泡样式的 UITableView 的简单实现。它基于 Jesse Squires 的 MessagesTableViewController 强烈构建,因为我需要深度定制视图,所以我决定创建一个新的库。

请注意

此库不再维护。我强烈建议您使用上述链接中的 Jesse 的库。希望采用此库?在问题部分联系我。

截图

AMBubbleTableViewController

AMBubbleTableDataSource

您需要提供一个实现 AMBubbleTableDataSource 的对象,该对象包含您想显示的所有数据。必需的调用是

- (NSInteger)numberOfRows;
- (AMBubbleCellType)cellTypeForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSString *)textForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSDate *)timestampForRowAtIndexPath:(NSIndexPath *)indexPath;

您还可以选择指定一个头像图像、用户名及其颜色

- (UIImage*)avatarForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSString*)usernameForRowAtIndexPath:(NSIndexPath *)indexPath;
- (UIColor*)usernameColorForRowAtIndexPath:(NSIndexPath *)indexPath;

AMBubbleTableDelegate

实现代理以接收用户的文本

- (void)didSendText:(NSString*)text;
- (void)swipedCellAtIndexPath:(NSIndexPath *)indexPath withFrame:(CGRect)frame andDirection:(UISwipeGestureRecognizerDirection)direction;
- (void)longPressedCellAtIndexPath:(NSIndexPath *)indexPath withFrame:(CGRect)frame;

主要样式

您可以通过以下方式更改 AMBubbleTableViewController 的样式

// After initialization
[self setTableStyle:AMBubbleTableStyleFlat];    // AMBubbleTableStyleDefault, AMBubbleTableStyleSquare, AMBubbleTableStyleFlat

自定义附属视图

AMBubbleTableViewController 使用另一个附属视图(它与标准附属视图分开)来显示头像和时间戳。您可以通过传入选项字典中的附加类来自定义此视图。您的类只需要是 UIView 的子类并实现 AMBubbleAccessory 协议

- (id)setOptions:(NSDictionary*)options;
- (void)setupView:(NSDictionary*)params;

其中 params 是包含 UIImage @"avatar" 和 NSString @"date" 的字典。

选项字典

可以通过传递一个 NSDictionary 到它来处理 AMBubbleTableViewController 的配置。默认值可以在 AMBubbleGlobals.m 中找到。以下是可能选项的简要描述

AMOptionsTableStyle             // @(AMBubbleTableCellStyle), Sets the table style. Defaults to AMBubbleTableCellDefault.
AMOptionsTimestampEachMessage   // @(BOOL), Enables the timestamp for each message. Defaults to @YES.
AMOptionsTimestampShortFont     // UIFont, Sets the short timestamp font. 
AMOptionsTimestampFont          // UIFont, Sets the full timestamp font.
AMOptionsAvatarSize             // @(float), The avatar size. Defaults to @50.
AMOptionsAccessoryClass         // NSString, The accessory view for each cell. Defaults to @"AMBubbleAccessoryView".
AMOptionsAccessorySize          // @(float), The accssory view size (used to compute the minimum cell height). Defaults to @50.
AMOptionsAccessoryMargin        // @(float), The accessory view margin. Defaults to @5.
AMOptionsTimestampHeight        // @(float), The height of the timestamp row. Defaults to @40.

样式选项

您还可以指定其他样式选项。AMBubbleTableViewController 包含三种样式,以下选项的默认值因样式而异。请在 AMBubbleGlobals.m 中查看更多信息。

AMOptionsImageIncoming          // UIImage, the left bubble stretchable image
AMOptionsImageOutgoing          // UIImage, the right bubble stretchable image
AMOptionsImageBar               // UIImage, the text bar background, resizable with cap insets
AMOptionsImageInput             // UIImage, the text view mask, resizable with cap insets
AMOptionsImageButton            // UIImage, the button image, resizable with cap insets
AMOptionsImageButtonHighlight   // UIImage, the highlighted button image, resizable with cap insets
AMOptionsTextFieldBackground    // UIColor, the textView color
AMOptionsTextFieldFont          // UIFont, the textView font
AMOptionsTextFieldFontColor     // UIColor, the textView font color
AMOptionsBubbleTableBackground  // UIColor, the tableView color
AMOptionsAccessoryPosition      // @(AMBubbleAccessoryPosition), defines wether the accessory should stay up or down
AMOptionsButtonOffset           // @(float), the vertical offset of the send button
AMOptionsBubbleTextColor        // UIColor, the main bubble's text color
AMOptionsBubbleTextFont         // UIFont, the main bubble's text font
AMOptionsUsernameFont           // UIFont, the username's text font
AMOptionsButtonFont             // UIFont, the button's text font
AMOptionsBubbleSwipeEnabled     // @(BOOL), enables the swipe detection on a cell
AMOptionsBubblePressEnabled     // @(BOOL), enables the long press detection on a cell
AMOptionsBubbleDetectionType    // @(int), the text detection type, refer to UIDataDetectorTypes. Defaults to UIDataDetectorTypeNone

变更日志

0.5

待办事项

  • 添加更多自定义

MIT许可协议

Copyright (c) 2013 Andrea Mazzini. All rights reserved.

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.