Dynamically change UITable cell height?

后端 未结 5 1518
心在旅途
心在旅途 2021-01-01 05:44

I need to resize the cell height based on the content size/length.tried several methods, which one gives the exact height without overlapping?

5条回答
  •  被撕碎了的回忆
    2021-01-01 06:33

    In your case you need to set the height of cell based on the label.

    Check the link :

    http://dcraziee.wordpress.com/2013/05/22/calculate-size-of-uillabel-base-on-text-in/

    There is a function named

    -(CGFloat)getHeightForLabel:(NSString *)_str font:(UIFont *)fontOfObject
    

    Use that function to calculate height as :

    -(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        CGFloat _height  = [self getHeightForLabel:self.label.text font:[self.label font]];
        return _height;
    }
    

提交回复
热议问题