首页 > 其他 > 详细

autolayout在cell高度变化中的应用(下)

时间:2015-05-13 12:05:13      阅读:278      评论:0      收藏:0      [点我收藏+]

有了autolayout,我们完全可以用xib去布局cell上的子空间,不用再去写冗余的创建代码及frame模型。

自己仅仅需要做的是:拿到cell最下面固定的子控件(一直存在),在返回高度的方法中,写如下代码即可

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomePageCell *cell = [tableView dequeueReusableCellWithIdentifier:kHomePageCell];

    HomePageCellModel *model = self.dataList[indexPath.row];
    cell.homePageCellModel = model;
    
    [cell layoutIfNeeded];
    return cell.locationContainer.y + cell.locationContainer.height + 13 + 13;
}

使用注意:如果label是多行的一定要设置preferredMaxLayoutWidth,如果存在多个多行label,都要设置,这样才能得到正确的布局

autolayout在cell高度变化中的应用(下)

原文:http://www.cnblogs.com/boy332/p/4499929.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!