My iOS app has a tableview with one UITableViewCell with the following layout (1 stackview containing 2 labels and 1 button)
When the user taps the button the number of lines of the central label goes from 0 to 2 and will look like this:
Now there are two problems here:
1) Resizing the UIStackView
2) Resizing the cell
I have found a not-optimal solution for problem 1, which consists of adding an empty view in the stack. (invalidateIntrinsicContentSize was not working).
let emptyView = UIView()
emptyView.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
stackView.addArrangedSubview(emptyView)
As you can see in the second screenshot the cell doesn't resize and I'm not sure if this is due to the stackview or the cell itself.
I would like to point the fact that I'm writing code inside the UITableViewCell subclass as the button event is handled inside it.
For the records The Tableview is using dynamic sizing:
// dynamic cell sizing
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return CGFloat(cellEstimatedHeight)
}