0

I have button with text in stack view, and on button init this text is short, but when I click on this button text is changing for longer text, but height of this button is not good.

I set this properties on button, but still not working

button.titleLabel?.lineBreakMode = .byWordWrapping
button.titleLabel?.textAlignment = .left
button.titleLabel?.numberOfLines = 0

How can I get dynamic size of button depending on text length?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Please, post screenshots of the button and the stack view constraints on the storyboard. Also, I'm not sure, but you probably need to call `view.setNeedsLayout()` when you change the button text. – kelin Oct 31 '18 at 19:09
  • `addSubview(stackView) stackView.addArrangedSubview(titleButton) stackView.snp.makeConstraints { make in make.top.bottom.leading.trailing.equalToSuperview() }` I don't use storyboards, I don't set any constraints for button. `view.setNeedsLayout` not working – jaskowice1 Nov 01 '18 at 12:06
  • You using some UI custom library? – kelin Nov 02 '18 at 13:08
  • No, I don't use any UI Custom library, only SnapKit. – jaskowice1 Nov 02 '18 at 15:48
  • It *is* custom. Try to connect the developers (post issue on GitHub) and tell about your problem. – kelin Nov 02 '18 at 19:38
  • This is resolution of this problem: https://stackoverflow.com/questions/27259333/uibutton-that-resizes-to-fit-its-titlelabel – jaskowice1 Nov 03 '18 at 18:01

0 Answers0