0

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. 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.

iOSDev
  • 3,617
  • 10
  • 51
  • 91

3 Answers3

9

I would highly advise this library:

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

I think it will suit your needs.

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
  • I suggest to don't give and of such type question. We should not use Stack overflow as google search. – Nitin May 10 '12 at 07:40
  • 1
    I think he got the point (-3 votes is enough). The funny part is actually giving me a -1. But whatever. – Rui Peres May 10 '12 at 07:42
  • @JackyBoy Agreed, the asker has already lost rep for this, and most likely this question will be closed and not deleted, and will therefore end up as a google search result for people looking for this in the future, and for some reason I can't seem to find it right now, but a while ago I downloaded a sample project similar to this from Github that didn't cost $30. So there are alternatives out there. – Mick MacCallum May 10 '12 at 08:36
  • @MDT I am just providing an answer for what he asked. He is free to choose mine as correct or not. I would take a -1 without problems if my answer was out of context, which is not. Hate the game not the player. – Rui Peres May 10 '12 at 08:51
  • @JackyBoy Sorry I didn't mean for that to be taken as disagreeing with you, I'm with you. I think that this is a perfectly acceptable answer, and I don't see a reason for the -1. I was merely pointing out, once again for future users, that alternatives exist if they look hard enough. +1 – Mick MacCallum May 10 '12 at 08:57
  • can u please see this link..have to implement this with some modification http://stackoverflow.com/questions/18181095/message-bubbles-for-ios-with-avtar-image-avtar-name-and-timestamp-on-each-buble – BhavikKama Oct 09 '13 at 10:23
6

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 "

You can add as many labels as required in custom UITableViewcell (or controls). 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.

Community
  • 1
  • 1
Abhishek Singh
  • 6,068
  • 1
  • 23
  • 25
3

check this - http://idevrecipes.com/2010/12/08/stretchable-images-and-buttons/ - and use the same method, but your image in custom table cell will be stretchable vertically - with some cap in the middle.. and then add this uiimage as a background to the cell