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

来源:互联网 发布:淘宝密码怎么找回来 编辑:程序博客网 时间:2024/04/29 19:32

什么是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
原创粉丝点击