开发过程中,策划/美术要求框内文字保持原有尺寸大小,如果文字放不下,则用省略号(...)代替剩余文字,代码如下:
private UILabel _labPlayerName;private void SetNickName() { string nickName = "这个名字有点长有点长有点长"; string strOut = string.Empty; bool bWarp = _labPlayerName.Wrap(nickName, out strOut, _labPlayerName.height); while (!bWarp) { strOut = nickName.Substring(0, nickName.Length - 1); nickName = strOut; strOut += "..."; bWarp = _labPlayerName.Wrap(strOut, out strOut, _labPlayerName.height); } _labPlayerName.text = strOut; }
时间: 2024-10-16 10:45:39