/// <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;
}
Einheitliche adaptive Texthöhe, stattdessen redundante Textauslassungen
おすすめ
転載: blog.csdn.net/weixin_47819574/article/details/129438747
ランキング