zoukankan      html  css  js  c++  java
  • 自定义cell自适应高度

    UITableView在许多App种被大量的应用着,呈现出现的效果也是多种多样的,不能局限于系统的一种样式,所以需要自定义cell

    自定义cell呈现的内容也是多种多样的,内容有多有少,所以需要一种能让自定义cell自适应高度的方法

    下面举例的是让自定义cell中的UILabel能够根据文字内容的多少自适应高度

    //求一段文本的显示高度
    + (CGFloat)heightForString:(NSString *)string {

    //字典dic中存的是UILabel中显示文字的字体信息 NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17],NSFontAttributeName, nil];
    CGRect rect = [string boundingRectWithSize:CGSizeMake(KimageWidth * 3, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil]; return rect.size.height; }
    //返回cell的高度
    + (CGFloat)cellHeightForStudent:(Student *)student {
        CGFloat totalHeight = 65 + [GirlTableViewCell heightForString:student.introduce];
        return totalHeight > 120 ? totalHeight :120;
    }

    下面是效果

  • 相关阅读:
    ②.kubernetes service
    c2p
    ⑤.docker dockerfile
    ④.docker volume
    ②.docker image
    ③.docker container
    ①.docker介绍
    三剑客之grep
    ⑦.shell 数组
    shell 正则
  • 原文地址:https://www.cnblogs.com/dabaomo/p/5206965.html
Copyright © 2011-2022 走看看