/// <summary>
/// 换行自适应Text高度
/// 多余文字 ... 代替
/// </summary>
/// <param name="value"></param>
/// <param name="targetText"></param>
/// <returns></returns>
public static string SetTextWithEllipsis(string value, Text targetText)
{
TextGenerator generator = new TextGenerator();
string textStr;
var settings = targetText.GetGenerationSettings(targetText.gameObject.GetComponent<RectTransform>().rect.size);
generator.Populate(value, settings);
var characterCountVisible = generator.characterCountVisible;
var updatedText = value;
if (value.Length > characterCountVisible)
{
updatedText = value.Substring(0, characterCountVisible - 3);
updatedText += "…";
}
textStr = updatedText;
return textStr;
}
unity 自适应Text高度,多余文字省略号替代
最新推荐文章于 2024-06-11 20:23:33 发布