码迷,mamicode.com
首页 > 移动开发 > 详细

ios 动态设置Cell的高度

时间:2015-03-31 16:04:04      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:ios

- (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;
    }
}

ios 动态设置Cell的高度

标签:ios

原文地址:http://blog.csdn.net/darongzi1314/article/details/44780199

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!