Reputation: 1773
I'm trying to dynamically add UIButtons
to UIStackView
, but came across some strange behavior. As the text inside button is dynamic too, it should be multiline (by default it's not). So I set break mode like this:
button.titleLabel?.lineBreakMode = NSLineBreakMode.byWordWrapping
stackView.addArrangedSubview(button)
The result looks like this (I made buttons different background color to better illustrate the problem):
Text exceeds button's borders and overlaps other views. How can this be fixed?
UIStackView is loaded from this simple xib:
Thanks in advance
Upvotes: 0
Views: 853
Reputation: 66
The titleLable is not constrained to the bounds of the button, that's the problem. You should extend the UIButton and override either layoutSubviews or intrinsicContentSize or just try to inject constraints.
Upvotes: 1