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)

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:

http://docs.unity3d.com/Manual/HOWTO-UIFitContentSize.html