Search Unity

How to resize button image/bg based on its content?

Discussion in 'UGUI & TextMesh Pro' started by pickassoreborn, Aug 20, 2015.

  1. pickassoreborn

    pickassoreborn

    Joined:
    Aug 20, 2015
    Posts:
    2
    Hey,

    Newcomer to Unity - please be gentle. I'm having an issue trying to get a 3-slice button image to dynamically adjust to a horizontal layout containing an icon to the left and a text string to the right. I thought I found the answer with the Content Size Fitter though the directions on Unity's documentation are less than helpful:

    "In order to do this, first add a Horizontal Layout Group to the UI element, then add a Content Size Fitter too. Set the Horizontal Fit, the Vertical Fit, ot[sic] both to the Preferred setting. You can add and tweak padding using the padding property in the Horizontal Layout Group."

    It sounds like I can add a Horizontal Layout Group and also a Content Size Fitter to the same "UI element" though Unity gives me an error regarding this. A step-by-step process to achieve this would be of great help to my artist brains.

    Also would like to achieve this within the layout/editor without any scripting.

    Cheers,
    Steve

    Quick update - think I'm having problems as the button is part of a vertical layout group which is why I'm getting that error. Would be nice if I could have the button behave within that vertical layout group. Will investigate some more.
     
    Last edited: Aug 21, 2015