w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
TextView inside a table cell fo tableview not displaying correctly

I agree with @railwayparade you should use

cell.textLabel.numberOfLines = 0;

Use heightForRowAtIndexPath to calculate the size the cell needs to be

-(CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
    // replace "THE_TEXT" with the text you are displaying and
"TEXT_LABEL_FONT" with the font you're using in the cell

    CGSize size = ["THE_TEXT" sizeWithFont:"TEXT_LABEL_FONT"
constrainedToSize:CGSizeMake(self.table.bounds.size.width, HUGE_VALF)
    return size.height;

You might want to subclass UITableViewCell and override layoutSubviews to set the textLabel to the exact right size, and add padding as you see fit

-(void)layoutSubviews // in your UITableViewCell subclass
    [super layoutSubviews];
    self.textLabel.frame =

Don't forget if you do add padding on the width in layout subviews, you'll have to change the constrained width in heightForRowAtIndexPath

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.