博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
动态设置Cell的高度
阅读量:4078 次
发布时间:2019-05-25

本文共 1401 字,大约阅读时间需要 4 分钟。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

       self.mainTitle=[[UILabel alloc]init];

            self.mainTitle.numberOfLines=0;
            self.mainTitle.font=[UIFont fontWithName:@"Hiragino Sans GB" size:14];
            self.mainTitle.text=cell_info.title;
            self.mainTitle.textColor=[UIColor grayColor];
            CGSize titleSize=[self.mainTitle.text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width-20, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: self.mainTitle.font} context:nil].size;
            self.rowHeight=titleSize.height;
            self.mainTitle.frame=CGRectMake(15, 3, titleSize.width,titleSize.height);
            [cell.contentView addSubview:self.mainTitle];

       CGRect cellFrame=[cell frame];

        cellFrame.origin=CGPointMake(0,0);
        cellFrame.size.height=self.mainTitle.frame.size.height+5+self.imgOne.frame.size.height+5;
        [cell setFrame:cellFrame];

       return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        return 160;
    }
    else{
//        if (indexPath.row==0) {
//            UITableViewCell *cell=[self tableView:self.tableView cellForRowAtIndexPath:indexPath];
//            return cell.frame.size.height;
//        }
        UITableViewCell *cell=[self tableView:self.tableView cellForRowAtIndexPath:indexPath];
        return cell.frame.size.height;
    }

}

原文链接:http://blog.csdn.net/darongzi1314/article/details/44780199

你可能感兴趣的文章
常用排序算法总结(一) 比较算法总结
查看>>
SSH原理与运用
查看>>
SIGN UP BEC2
查看>>
出现( linker command failed with exit code 1)错误总结
查看>>
iOS开发中一些常见的并行处理
查看>>
iOS获取手机的Mac地址
查看>>
ios7.1发布企业证书测试包的问题
查看>>
如何自定义iOS中的控件
查看>>
iOS 开发百问
查看>>
Mac环境下svn的使用
查看>>
github简单使用教程
查看>>
如何高效利用GitHub
查看>>
环境分支-git版本管理
查看>>
Spring AOP + Redis + 注解实现redis 分布式锁
查看>>
支付宝生活号服务号 用户信息获取 oauth2 登录对接 springboot java
查看>>
CodeForces #196(Div. 2) 337D Book of Evil (树形dp)
查看>>
uva 12260 - Free Goodies (dp,贪心 | 好题)
查看>>
uva-1427 Parade (单调队列优化dp)
查看>>
【设计模式】学习笔记14:状态模式(State)
查看>>
poj 1976 A Mini Locomotive (dp 二维01背包)
查看>>