zoukankan      html  css  js  c++  java
  • 根据label不同的字符串的多少自适应cell的高度

     //获取评论内容 根据内容来设置label的高度  设置tag值

            NSString *string = [NSString stringWithFormat:@"%@",label.text];

            CGRect rect = [string boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width -70, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil];

            cell.content.frame = CGRectMake(60, 40,[UIScreen mainScreen].bounds.size.width -70 , rect.size.height);

            cell.content.tag = 11;

            cell.content.text =string;

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

    {

        //根据tag值来获取cell的高度

        UILabel *nameLabel = (UILabel *)[self.view viewWithTag:1];

        UILabel *contLabel = (UILabel *)[self.view viewWithTag:11];

        return nameLabel.frame.size.height+contLabel.frame.size.height + 30;

    }

  • 相关阅读:
    TCP/IP协议详解
    linux高性能服务器编程--初见
    聚合类
    类class 2
    继承
    构造函数再探
    静态成员与友元
    MySQL图形工具SQLyog破解版
    MySQL注释符号
    数据库中多对多关系的中间表的命名规则
  • 原文地址:https://www.cnblogs.com/Lovexiaohuzi/p/5474464.html
Copyright © 2011-2022 走看看