Skip to main content
Question

Auto layout button text that can resize both left and right from the centre?


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?

This topic has been closed for replies.

6 replies

Pavel_Kiselev

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


  • Author
  • 3 replies
  • April 6, 2023

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.


dennsi
  • Active Member
  • 256 replies
  • April 6, 2023

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.


  • Author
  • 3 replies
  • April 6, 2023

Did some more tinkering. This worked! 😍


dennsi
  • Active Member
  • 256 replies
  • April 6, 2023

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. 😀


  • Author
  • 3 replies
  • April 6, 2023

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings