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;
    }

    下面是效果

  • 相关阅读:
    1
    前端必读书籍推荐
    cn
    网站爬虫优化
    es学习
    适应移动端
    chrome禁止缓存,每次都最新的
    vue 源码环境
    [Java] 设计模式之工厂系列 04 (自定义模拟 spring 读取xml文件 beanFactory)
    [Java] JDOM 读取 xml 文件 示例程序初步
  • 原文地址:https://www.cnblogs.com/dabaomo/p/5206965.html
Copyright © 2011-2022 走看看