0

I would like to create comments view as like thisenter image description here
I would like to create dynamic height UItableviewcell with comments label should support gif emoji and images. How can I achieve this. I have tried with DTCoretext. But I couldn't succeed. Have any other way ? kindly help me. Thanks in advance.

Rathakrishnan Ramasamy
  • 1,612
  • 2
  • 25
  • 46

1 Answers1

0

You will need to calculate the height of the cell with the content from it. In my case I was only showing a UITextView, but this could be extended for custom/multiple views as well.

In my example, I fit my text into a size with a maximum width and add 75 units of padding around it to determine my maximum cell size. To make sure the cell doesn't get too big, I finally clamp it to a max height of 400

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([indexPath row] == _currentSelection) {
        UITextView * text = [[UITextView alloc] init];
        PatchNotes * note = [_patchNotes objectAtIndex:[indexPath row]];

        [text setText:note.topChanges];

        CGSize size = [text sizeThatFits:CGSizeMake(277, CGFLOAT_MAX)];

        CGFloat height = 75 + size.height;

        return MIN( height, 400 );
    }

    return 50;
}

Hope this can help :)

SilkyPantsDan
  • 561
  • 4
  • 5
  • I have managed to get dynamic height. My problem is adding attributed lable or webview that support emoji and images into UITableviewcell.. do you have any idea on it ? – Rathakrishnan Ramasamy Sep 22 '15 at 03:10
  • UITextView should be able to handle both images and emoji characters (http://stackoverflow.com/questions/23909856/how-to-display-the-emoji-and-special-characters-in-uilabel-and-uitextviews) by default - with images being added as attachments to the attibuted text (http://stackoverflow.com/questions/24010035/how-to-add-image-and-text-in-uitextview-in-ios). – SilkyPantsDan Sep 22 '15 at 03:42