zoukankan      html  css  js  c++  java
  • 纯代码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;
         
         
    }

  • 相关阅读:
    「CH6801」棋盘覆盖
    「POJ3613」Cow Relays
    「Luogu4556」Vani有约会-雨天的尾巴
    The Proof of Fibonacci GCD
    Ubuntu flatabulous 主题
    CSP-S 2019 复赛游记
    「Luogu1402」酒店之王
    HDU/5499/模拟
    cfedu/A/求和
    HDU<1372>/bfs
  • 原文地址:https://www.cnblogs.com/weiboyuan/p/4910250.html
Copyright © 2011-2022 走看看