Unity UILabel 输入空格自动换行的解决

NGUI 会将空格自动换成换行符号, 这样就会使得我们想在一段文字的开头输入两个空格的时候出现问题.

找到NGUI 的NGUIText.cs脚本文件中的

ReplaceSpaceWithNewline

函数, 修改如下:

    /// 
    /// Convenience function that ends the line by replacing a space with a newline character.
    /// 

    [DebuggerHidden]
    [DebuggerStepThrough]
    static void ReplaceSpaceWithNewline (ref StringBuilder s)
    {
        //int i = s.Length - 1;
        //if (i > 0 && IsSpace(s[i])) s[i] = '\n';

    }

将该函数里面的内容注释掉就可以了.

测试结果

编辑器中的UILabel

Unity UILabel 输入空格自动换行的解决_第1张图片

游戏中的 UILabel

这里写图片描述

可以看到空格生效了

你可能感兴趣的:(Unity)