Search code examples
iosuitableviewios6resizeuitextview

IOS Resizing UITextView for IM Program


Currently I have a program that displays chat messages between users. It puts each message in a cell and stores the message in a UITextView that's contained in the cell. The UITextView has a background that is applied to the view. How exactly do I resize the text view so that the background is resized and the dynamic content is properly placed in side? Also, what would you recommend would be be the best way to resize the cell along with the view. I know there are a lot of similar posts but I can't seem to find anything that works with this specific situation. Either they resize the content without view and background or when the cell resizes it is glitchy and inconsistent with the size of the text views content. Here is the code im using inside cellForRowAtIndexPath.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MessageCell *cell;
    Message *message = [_messages objectAtIndex:(indexPath.row)];

    if ([[[PFUser currentUser] objectId] isEqualToString:message.sender])
    {
        cell = (MessageCell *)[tableView dequeueReusableCellWithIdentifier:@"SenderCell"];
        cell.message.text = message.message;
    }
    else
    {
        cell = (MessageCell *)[tableView dequeueReusableCellWithIdentifier:@"RecipientCell"];
        cell.message.text = message.message;
    }

    return cell;
}

Solution

  • Checkout the free Sensible TableView framework. The have a text view that automatically resizes as your content grows.