Post

Replies

Boosts

Views

Activity

Reply to UIButton not respecting maximumContentSizeCategory
@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! }
Jul ’23
Reply to UIButton not respecting maximumContentSizeCategory
@Rincewind Unfortunately I'm unable to post the code publicly, but in trying to reduce the issue I've only been able to do so by setting the maximumContentSizeCategory of the cell itself (in cellForRowAtIndexPath) vs. setting it on the view controller's root view in viewDidLoad. I'm still trying to figure out why that is.
Jul ’23