agentfll agentfll - 1 year ago 74
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?

Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download