简体   繁体   中英

How to stretch cell to full screen?

I have a UIView inside a table cell. I need to stretch my cell on full screen.

In my table view I have this:

table.rowHeight = UITableView.automaticDimension

But now I can't to make this.

My code is:

containerView.snp.makeConstraints { make in
    make.edges.equalToSuperview()
}
    
verticalStackView.snp.makeConstraints { make in
    make.center.equalToSuperview()
    make.leading.trailing.equalToSuperview().inset(20)
}

I need to get this:

在此处输入图像描述

But I have:

在此处输入图像描述

So UITableView.automaticDimension will tell the program to find the minimum height this cell can be without any clipping (to simplify it)

What you'll need to do is intercept the cell in

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if self.myData.isEmpty {
        return tableView.frame.height
    }

    return UITableView.automaticDimension
}

Assuming you show that cell when there Is no data to be shown, you can just do a check to see if you data array isEmpty, and if so, make the cell the height of the tableView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM