Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

New UIButton title left aligned

Hello There,

I was trying to do a Button with title left aligned. With the old UIButton, I would have used the title-/contentEdgeInsets to achieve this, but with the new button these values are deprecated and do not work anymore. As far as I understood, with the new button only the spacing between the elements (sub-, title and image) is controllable. I also tried just setting the buttons width to the same width as the label, what would be possible in my case since it should be kind of a "hyperlink-button" which has no background or border. This works so far, but once the user interacts with the button, the title label gets multiline, which is on the one hand not wanted and on the other hand of course does not look left aligned anymore. (Besides the buttons height is fix in my case which leads to clipping of the title)

So here again in short: Is there any way to make the title of the new UIButton left aligned inside of the button?

Thank you very much in advance.

Answered by Frameworks Engineer in 768028022

When using button configurations, the layout responds to UIControl.contentVerticalAlignment and UIControl.contentHorizontalAlignment for aligning the content within the content rect. So if you want a leading aligned button, just set button.contentHorizontalAlignment = .leading

Accepted Answer

When using button configurations, the layout responds to UIControl.contentVerticalAlignment and UIControl.contentHorizontalAlignment for aligning the content within the content rect. So if you want a leading aligned button, just set button.contentHorizontalAlignment = .leading

Also, UIButton Style needs to be Default, not Plain, for this to work.

New UIButton title left aligned
 
 
Q