简体   繁体   English

与UITableViewCells聊天气泡

[英]Chat Bubbles with UITableViewCells

I want to have chat bubbles with a custom bubble image to be used to display chat messages. 我想使用带有自定义气泡图像的聊天气泡来显示聊天消息。 As a beginner, I am thinking of having a UITableView with custom cells. 作为一个初学者,我正在考虑使用带有自定义单元格的UITableView。 The cell will have bubble image. 单元格将显示气泡图像。 And within that image, I want to have chat message, date&time and status. 在该图像中,我想要聊天消息,日期和时间以及状态。

Also, the size of bubble image will shrink or expand depending on message size. 此外,气泡图像的大小将根据邮件大小而缩小或扩大。

How do I achieve this? 我该如何实现? Is there any good tutorial to achieve this? 有什么好的教程可以做到这一点吗?

Please help. 请帮忙。

Thanks in advance. 提前致谢。

I would highly advise this library: 我强烈建议这个图书馆:

http://www.cocoacontrols.com/platforms/ios/controls/stbubbletableviewcell http://www.cocoacontrols.com/platforms/ios/controls/stbubbletableviewcell

I think it will suit your needs. 我认为它将满足您的需求。

You can of course have a structure but the it will be quite odd because the size of table will be according to size of biggest cell , also the size of table will have to be defined during allocation so what you will be doing is placing an image according to the size of text and it will be quite odd as rest of cell will be simple white. 您当然可以有一个结构,但是它会很奇怪,因为表的大小将根据最大单元格的大小确定,表的大小也必须在分配期间定义,因此您要做的是放置图像根据文本的大小,这将是很奇怪的,因为单元格的其余部分将是简单的白色。

Now . 现在。 You will have to implement the logic to change the size of image in layoutSubviews Method of UITableViewCell as You can get the size of text from the chat message using sizeWithFont method of NSString PLease see String size in label and then you will have to set the frame of each cell or image in the delegate method of uitableview "- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath " 您将必须实现更改UITableViewCell的layoutSubviews方法中图像大小的逻辑,因为您可以使用NSString Please的sizeWithFont方法从聊天消息中获取文本的大小请参见标签中的字符串大小 ,然后必须设置框架uitableview的委托方法中的每个单元格或图像的“-((UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath“

You can add as many labels as required in custom UITableViewcell (or controls). 您可以根据需要在自定义UITableViewcell(或控件)中添加任意数量的标签。 Custom cell Tutorial 自定义单元教程

Alternatively you can create a custom view where in you can define methods to add subviews with the image as background cropped to match the size of message , below each message and create an array of strings or dictionary of string to keep a track of messages from different users. 另外,您也可以创建一个自定义视图,在其中可以定义方法,以添加子视图,并在背景中裁剪图像以匹配消息的大小,以匹配消息的大小,并在每个消息下方创建一个字符串数组或字符串字典,以跟踪来自不同消息的消息用户。

检查此内容-http://idevrecipes.com/2010/12/08/stretchable-images-and-buttons/-并使用相同的方法,但是自定义表格单元格中的图像可以垂直拉伸-中间有一些顶盖..然后将此uiimage作为背景添加到单元格中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM