How to stretch cell to full screen?

264 views Asked by At

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:

enter image description here

But I have:

enter image description here

1

There are 1 answers

1
Ayrton CB On

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