Skip to main content

I know with auto layout button text can be aligned left and grow to the right, or aligned right and grow left. Is it possible for button text to grow from the centre, left and right?

Yep, easy. But it’s not about button, but the parent frame where the button sits


I think I sort of tried that. I have text inside a frame inside an auto layout. If I have the frame spacing mode set to ‘space between’ the text will from the centre (exactly what I want) but my rectangle won’t grow with the text.


Button:

Auto Layout Frame set to Hug Content (= resize with different text)

hug


Parent frame:

Auto Layout with Alignment top center or center center


If the parent frame doesn’t utilize Auto Layout you’ll need to adjust the constraints of the Button and set left and right to center. Change the button position and align it to the center as well.


The alignment of the text doesn’t matter here by the way.


Did some more tinkering. This worked! 😍



Spacing mode doesn’t need to be set to “space between” if you’re using one element only.

“Packed” is the more correct way to do it. If theres only one element the result is the same though. 😀


The only problem with setting to ‘packed’ means the text will only grow to the right 🙂 whatever gets the job done ay! 🛠️ 😀


Reply