一行搞定cell自适应高度 -- ZXPAutoLayout框架的使用

什么是ZXPAutoLayout ?


本篇只讲解如何使用ZXPAutoLayout进行cell的自适应. ZXPAutoLayout的简单介绍和入门请看这篇文章,请点我. github地址: 请点我

1.注册cell


cell 自适应高度之前请确保调用了tableviewregisterClass: forCellReuseIdentifier: 或者 registerNib: forCellReuseIdentifier: 方法来注册cell

2. 在tableview的返回高度的方法调用zxp_cellHeightWithIdentifier: config:方法即可

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    //cell 自适应的高度 + 10的距离, 调用此方法之前,请确保调用了  registerClass: forCellReuseIdentifier: 或者 registerNib: forCellReuseIdentifier: 方法来注册cell
    return [tableView zxp_cellHeightWithIdentifier:kTestCellID config:^(__kindof UITableViewCell *cell) {
        [self configTestCell:cell indexPath:indexPath];
    } space:10];
}

3.返回cell里指定view的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    //cell 自适应到textLabel的高度 + 10的距离, 调用此方法之前,请确保调用了  registerClass: forCellReuseIdentifier: 或者 registerNib: forCellReuseIdentifier: 方法来注册cell
    [tableView zxp_cellHeightWithIdentifier:kTestCellID configAndReturnView:^UIView *(__kindof UITableViewCell *cell) {
        return cell.textLabel;
    } space:10];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值