/// <summary>
/// 文本超出部分省略号
/// </summary>
/// <param name="textTemp">目标文本框</param>
/// <param name="value">文本</param>
private void SetTextWithEllipsis(Text temp, string value)
{
var generator = new TextGenerator();
var rect = temp.GetComponent<RectTransform>();
var setting = temp.GetGenerationSettings(rect.rect.size);
generator.Populate(value, setting);
string updateText = value;
var charCount = generator.characterCountVisible;
//Debug.LogError(charCount);
if (value.Length > charCount + 1)
{
updateText = value.Substring(0, charCount - 2);
updateText += "...";
}
else
{
temp.horizontalOverflow = HorizontalWrapMode.Overflow;
}
temp.text = updateText;
}
unity 高版本UnityEngine.UGUI Text组件超出边界...代替
最新推荐文章于 2024-08-21 17:25:45 发布