agentfll agentfll - 17 days ago 5
iOS Question

Make UITableViewCell expand when text exceeds space

I have a

and it is
. When I try to put text longer than the
, it truncates it. How do I make the cell expand to accommodate this text?


You can not expand cell's width more than iphone's screen... What you can do is 1> make font smaller 2> make your text multiple lines

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

    CGRect contentRect = CGRectMake(80.0, 0.0, 240, 40);
    UILabel *textView = [[UILabel alloc] initWithFrame:contentRect];

    textView.text = mytext;
    textView.numberOfLines = 2;
    textView.textColor = [UIColor grayColor];
    textView.font = [UIFont systemFontOfSize:12];
        [cell.contentView addSubview:textView];
    [textView release];