cell高度随文字变化

来源:互联网 发布:互联网公司待遇知乎 编辑:程序博客网 时间:2024/05/04 10:59

//设置cell行高的方法

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row ==0) {

        float height = [selfheightForString:self.infoModel.postInfoDescfontSize:17andWidth:SCREEN_WIDTH];

        return height;

    }

}

//判断文字的高度

-(float)heightForString:(NSString *)string fontSize:(float)fontSize andWidth:(float)width

{

    UITextView *detailTextView = [[UITextViewalloc]initWithFrame:CGRectMake(0,0, width, 0)];

    detailTextView.font = [UIFontsystemFontOfSize:fontSize];

    detailTextView.text = string;

    CGSize deSize = [detailTextViewsizeThatFits:CGSizeMake(width,CGFLOAT_MAX)];

    return deSize.height;

}



0 0
原创粉丝点击