S
S
Suren2018-06-22 17:12:35
Unity
Suren, 2018-06-22 17:12:35

How to expand the sprite to fit the text?

There is such a sprite 5b2d035756466705477317.png
. It contains UI Text, I need to change the size of the sprite depending on the size of the text.
I tried to make a Sprite Sliced ​​while broadcasting to the sprite component of the Content Size Fitter, but it didn't help, please help))))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil Basmanov, 2018-06-22
Jagaryan @saylar

A bit clumsy, but it works:
Insert text into a Layout with ContentSizeFitter, and hang a LayoutElement on the background with a flag to ignore the layout.

P
Pavel, 2018-06-22
@youkerni

If using ContentSizeFitter - put the text in UI.Text, make a short delay in the coroutine (for the new text size to be calculated). After updating the text size - set the sprite on the background to the size you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question