- Home /
Why isn't the text preferred size calculating correctly?
I've been trying to add Tooltip functionality to my game, where the background of the tooltip automatically resizes to fit in the text. I'm using the code below to do so:
private void ShowTooltip(string tooltipString)
{
...
float textPaddingSize = 4f;
Vector2 backgroundSize = new Vector2(tooltipText.preferredWidth + textPaddingSize*2f, tooltipText.preferredHeight + textPaddingSize * 2f);
backgroundRectTransform.sizeDelta = backgroundSize;
...
}
However, I'm having a problem with the resizing. If the horizontal text is set to 'overflow', it looks like this:
Now this is sized correctly, but it's not what I'm looking for since it's just too long. However, when I set the text to wrap horizontally instead, this happens:
The height has adjusted correctly, but the length has remained as if the text was still using the overflow property.
Does anyone know how I could fix this?
Your answer
Follow this Question
Related Questions
I need to resize my text to button to be visible using Unity 4.6 UI 2 Answers
Multiple gui instantiation issues 0 Answers
Instantiated UI objects with image components not appearing, rest of object works fine. 0 Answers
How do i do tooltips on UI.Text objects? 1 Answer
UI fade with CanvasGroup vs of Image.color.alpha or Text.color.alpha performance 1 Answer