How to adjust the height of the cell table when loading from the custom cells?

后端 未结 3 1276
臣服心动
臣服心动 2021-01-27 09:07

I have an application in which I am loading a UITableView from 3 types custom cells. I made 3 custom classes for that and added all the elements Progra

3条回答
  •  不思量自难忘°
    2021-01-27 09:49

    you can calculate height by using below function

    -(CGSize)SizeOfString:(NSString *)string withFont:(UIFont *)font constrainedToWidth:(CGFloat)width 
    {
        CGSize size = [string sizeWithFont:font constrainedToSize:CGSizeMake(width, 4000) lineBreakMode:UILineBreakModeWordWrap];
        return CGSizeMake(width, size.height + 10);
    }
    

    Call

    CGSize size = [self SizeOfString:your_text withFont:your_font constrainedToWidth:width_of_showing_area];
    

提交回复
热议问题