- Home /
uGUI Button size based on text size
Is it possible to create a uGUI button that's about exactly as large as the text?
How do you determine the dimensions of arbitrary text?
How do you match font dimension to uGUI pixel dimension to size the button (if necessary)
Answer by pfreese · Mar 21, 2015 at 02:11 AM
You can do this without any code by adding a ContentSizeFitter and a LayoutGroup (Horizontal or Vertical -- doesn't matter) to the button GameObject. The padding on the LayoutGroup lets you adjust the internal border between the button and the text.
See Fit to size of UI element with child Text on this page:
Your answer
Follow this Question
Related Questions
gui text button dont work 1 Answer
Text pop up when mouse over gui button 2 Answers
IPointerClickHandler error 2 Answers
GUI Button appears when Paused 1 Answer
Get/Set Button Text with uGUI 4.6 1 Answer