zoukankan      html  css  js  c++  java
  • 动态调整tableviewcell高度

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
              
            static NSString *CellIdentifier = @"Cell";  
              
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];  
            if (cell == nil) {  
                cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];  
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];  
                label.tag = 1;  
                label.lineBreakMode = UILineBreakModeWordWrap;  
                label.highlightedTextColor = [UIColor whiteColor];  
                label.numberOfLines = 0;  
                label.opaque = NO; // 选中Opaque表示视图后面的任何内容都不应该绘制  
                label.backgroundColor = [UIColor clearColor];  
                [cell.contentView addSubview:label];  
                [label release];  
            }  
              
            UILabel *label = (UILabel *)[cell viewWithTag:1];  
            NSString *text;  
            text = [textArray objectAtIndex:indexPath.row];  
            CGRect cellFrame = [cell frame];  
            cellFrame.origin = CGPointMake(0, 0);  
              
            label.text = text;  
            CGRect rect = CGRectInset(cellFrame, 2, 2);  
            label.frame = rect;  
            [label sizeToFit];  
            if (label.frame.size.height > 46) {  
                cellFrame.size.height = 50 + label.frame.size.height - 46;  
            }  
            else {  
                cellFrame.size.height = 50;  
            }  
            [cell setFrame:cellFrame];  
              
            return cell;  
        }  
          
        - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath  
        {  
            UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];  
            //UITableViewCell *cell = [self cellForRowAtIndexPath:indexPath];  
            return cell.frame.size.height;  
        }  
  • 相关阅读:
    HO引擎近况20210912
    查询超时问题的处理
    ubuntu根据关键词批量杀进程
    创建notebook适用的虚拟环境
    信赖域策略优化(Trust Region Policy Optimization, TRPO)
    强化学习(Reinforcement Learning)
    生成对抗网络(GAN与W-GAN)
    卷积神经网络CNN
    循环神经网络RNN
    PyTorch自动求导
  • 原文地址:https://www.cnblogs.com/gaoxiao228/p/2587576.html
Copyright © 2011-2022 走看看