Mani
Mani

Reputation: 17595

Dynamic height for tableview cell based on Stackview's height

Tableview cell not expanding based on the Stackview's height. The cell has container view for holding stack view, I'll add subviews programmatically to Stackview on cellForRowAt:. If no views added to the StackView, Its height should be 0. Otherwise, it should be some based on subview's height. My layout is below.

enter image description here

Xib file is below. It shows the Stackview's height as zero in this layout.

enter image description here

The problem is When I am adding Imageview to Stackview during cellForRowAt:, It gets adding but cell's height not expanding.

Note:

It's horizontal stack view

Upvotes: 0

Views: 4594

Answers (1)

Manish Mahajan
Manish Mahajan

Reputation: 2092

Make sure content in Stackview having bottom and top constraint to Stackview....

When you assign top and bottom constraint for content in Stackview, Stackview height automatically increases as its content size..

And no need to extra suggestion that tableview cell height should be automatic set.. means look below code.....

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

Upvotes: 6

Related Questions