• 纯代码TableView自适应高度(很老的使用方法)


    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return self.arr.count;
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
        cell.textLabel.numberOfLines = 100;
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        cell.textLabel.text = self.arr[indexPath.row];
        return cell;
    }
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
         
        NSString* text = self.arr[indexPath.row];
         
        CGSize constraint = CGSizeMake(375-40, 100);
         
         
        NSAttributedString* attributedText = [[NSAttributedString alloc]initWithString:text attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}];
         
        CGRect rect = [attributedText boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin context:nil];
         
        CGSize size = rect.size;
         
        CGFloat height = MAX(size.height, 20);
        NSLog(@"%f",height);
        return height+10;
         
         
    }

  • 相关阅读:
    Redis 集群模式
    Redis 哨兵模式
    加密盐的意义
    GeoJSON扩展几何图形格式
    GeoJSON格式规范说明
    个人作业-记账本
    疫情数据爬取
    数据库的修改
    《构建之法》读书笔记(三)
    《构建之法》读书笔记(二)
  • 原文地址:https://www.cnblogs.com/weiboyuan/p/4910250.html
Copyright © 2020-2023  润新知