How To Set Number Of Lines in UIButtonConfiguration

Hello! This is a follow up to this thread but how do you set the number of lines in a UIButtonConfiguration? I'm assuming that maybe we can do this through using attributedTitle/NSAttributedString, but not sure which property or specific attribute to use. Can I get any help towards setting the amount of lines? Any help is appreciated!

Yes, you can do with setTitle or setAttributedTitle

        button.setTitle("Multi\nLines", for: .normal)

Doesn't that just break the line up with the delimiter "\n"? My question was if we could do something similar to UILabel.numberofLines = 0.

Claude's solution would be to induce additional lines of text, but there is no means to set a completely custom number of lines. UIButtonConfiguration only supports single lines of text (by setting [sub]titleLineBreakMode property to a non-Wrapping mode) or unbounded lines of text.

Being able to enforce numberOfLines would be desirable. It seems like a pretty common need to enforce a button to fit on a single line and I would think having a button wrap multiline would be more uncommon.

In my case a button with a configuration initially displays with 1 line, but after toggling the Dynamic type setting to a smaller value, then increasing it back to the original value causes the button to start character wrapping even though there is plenty of room to fit all text on one line.

It seems that UIButton (with a button configuration) can't really properly respond to the -sizeToFit method. Calling -sizeToFit just constrains the button to the current width and increases the height which is the opposite of what I often want.

How To Set Number Of Lines in UIButtonConfiguration
 
 
Q