Dynamically size uitableViewCell according to UILabel (With paragraph spacing)

前端 未结 4 1144
粉色の甜心
粉色の甜心 2020-11-29 13:24

I have a UITableView which is populated by text and images from a JSON file. The TableView Cell is currently sizing correctly for "posts" that do not contain many

4条回答
  •  迷失自我
    2020-11-29 13:48

    @Shan had a good answer but it didn't entirely worked for me.

    This is the code I used for calculating the cell height

    -(float)height :(NSMutableAttributedString*)string
    {
        CGRect rect = [string boundingRectWithSize:(CGSize){table.frame.size.width - 110, MAXFLOAT} options:NSStringDrawingUsesLineFragmentOrigin context:nil];
        return rect.size.height;
    }
    

    I do the -110 because that will give equal space at sides top and bottom.

    Hope this helps.

提交回复
热议问题