DavydLiu / DLRadioButton

Radio Button for iOS
MIT License
948 stars 202 forks source link

Multiline buttons #138

Open timautin opened 6 years ago

timautin commented 6 years ago

When having multiline buttons, the text of the titleLabel grows outside of the button. I solved it by adding a few auto layout constraints (using a custom extension but you'll get the idea):

radioButton.titleLabel!.translatesAutoresizingMaskIntoConstraints = false;
radioButton.imageView!.translatesAutoresizingMaskIntoConstraints = false;
radioButton.constrain(soThat: .height, of: radioButton, is: .greaterThanOrEqual, to: .height, of: radioButton.titleLabel);
radioButton.constrain(soThat: .trailing, of: radioButton.titleLabel!, is: .equal, to: .trailing, of: radioButton);
radioButton.constrain(soThat: .width, of: radioButton.imageView!, is: .equal, to: radioButton.iconSize);
nikoagge commented 6 years ago

Or you can put all buttons in a Stackview, select Word Wrap on the Line Break each button's option and give Stackview specific width, at least that worked for me.

timautin commented 6 years ago

Ah yes, simpler solution for those targeting iOS 9. I can't use it since I still support iOS 8.