Custom cell-of unequal height (storyboard)

Source: Internet
Author: User

A few additional steps are required to compare a custom high-level cell (IOS8 is supported at the beginning)
    • To add a spacing constraint between a child control and a Contentview

    • Set the true implementation height of the Tableviewcell and estimate the row height
// 告诉tableView所有cell的真实高度是自动计算(根据设置的约束来计算)self.tableView.rowHeight = UITableViewAutomaticDimension;// 告诉tableView所有cell的估算高度self.tableView.estimatedRowHeight = 44;
If you want to support iOS8 before
    • If there is a wrap label inside the cell, you need to set the Preferredmaxlayoutwidth property
- (void)awakeFromNib{    // 手动设置文字的最大宽度(目的是:让label知道自己文字的最大宽度,进而能够计算出自己的frame)    self.text_label.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - 20;}
    • Set the cell estimate height for TableView
// 告诉tableView所有cell的估算高度(设置了估算高度,就可以减少tableView:heightForRowAtIndexPath:方法的调用次数)self.tableView.estimatedRowHeight = 200;
    • Calculating the cell height in the proxy method
XMGStatusCell *cell;- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    // 创建一个cell(cell的作用:根据模型数据布局所有的子控件,进而计算出cell的高度)    if (!cell) {        cell = [tableView dequeueReusableCellWithIdentifier:ID];    }    // 设置模型数据    cell.status = self.statuses[indexPath.row];    return cell.height;}- (CGFloat)height{    // 强制布局cell内部的所有子控件(label根据文字多少计算出自己最真实的尺寸)    [self layoutIfNeeded];    // 计算cell的高度    if (self.status.picture) {        return CGRectGetMaxY(self.pictureImageView.frame) + 10;    } else {        return CGRectGetMaxY(self.text_label.frame) + 10;    }}
End

Custom cell-of unequal height (storyboard)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.