@Rincewind Here's code for reproducing the issue by setting the maximum size on the cell:
class ViewController: UIViewController {
func addButtons(to stack: UIStackView) {
let titles = ["Button 1", "Button 2", "Button 3"]
for title in titles {
let button = button(title: title)
let heightConstraint = NSLayoutConstraint(
item: button,
attribute: NSLayoutConstraint.Attribute.height,
relatedBy: NSLayoutConstraint.Relation.greaterThanOrEqual,
toItem: nil,
attribute: NSLayoutConstraint.Attribute.notAnAttribute,
multiplier: 1,
constant: 48
)
button.addConstraint(heightConstraint)
stack.addArrangedSubview(button)
}
}
func button(title: String) -> UIButton {
var configuration = UIButton.Configuration.plain()
configuration.titleAlignment = .leading
configuration.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
var outgoing = incoming
outgoing.foregroundColor = UIColor.blue
outgoing.font = UIFont.preferredFont(forTextStyle: .body)
return outgoing
}
let button = UIButton(configuration: configuration)
button.setTitle(title, for: .normal)
return button
}
}
extension ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? TextCell else { return UITableViewCell() }
cell.maximumContentSizeCategory = .extraLarge
addButtons(to: cell.stackView)
return cell
}
}
class TextCell: UITableViewCell {
@IBOutlet var stackView: UIStackView!
}