Re: Help with iOS 15-style UIButton?

Alex Zavatone

I did this in UIKit by making the button’s frame.size.width the frame.size.width of the content within + appropriate space buffers.

One trick is if the text component is a UILabel, making the lines of text allowed to be 1 and the linebreak mode as you have.

Have you sent the lines of text to 1?

Let us know.

Alex Zavatone

On Jul 18, 2021, at 12:48 PM, Rick Aurbach via <rlaurb@...> wrote:

I am trying to construct a button using the new iOS15 button API. (Xcode 13ß3, UIKit & Storyboards)
The button has a title (aligned .leading) and an image (aligned .trailing). The button has the following layout constraints:
  • a fixed leading constraint (to a label that provides prompt text)
  • a center-vertically constraint (to that same label)
  • a trailing constraint ( >= a margin value)
What I’m trying to accomplish is that the button should adjust its width based on the title content, not wrapping until the width causes the trailing constraint to be violated.
What actually happens is the the button’s text wraps. It acts as if it prefers wrapping to changing its size.
There are mentions in the documentation about disabling text wrapping for the button, but the obvious things, such as
button.titleLabel?.lineBreakMode = .byTruncatingMiddle
don’t work.
Has anyone whose tried working with iOS 15 buttons have any suggestions?

Join { to automatically receive all group messages.