UGUI Bubble Text

Above:

item1 is the bubble basemap, txt text, icon avatar

 

item1 does not need to be set

txt needs to add this component

Icon avatar needs to set these two items

 

 In this way, the position of the picture can be automatically changed with the size of the text.

code show as below:

Text txt = item.transform.GetChildByName("txt").GetComponent<Text>();
txt.text = content;
//下面这段必须有
LayoutRebuilder.ForceRebuildLayoutImmediate(txt.GetComponent<RectTransform>());

item.GetComponent<RectTransform>().sizeDelta = new Vector2(txt.GetComponent<RectTransform>().rect.size.x + 100, item.GetComponent<RectTransform>().rect.size.y);

Guess you like

Origin blog.csdn.net/cuijiahao/article/details/120969462