美文网首页
NGUI文本由右向左竖排显示

NGUI文本由右向左竖排显示

作者: 一见有血 | 来源:发表于2018-04-13 20:31 被阅读0次

思路:

1,将要显示的文本由前向后拆分为若干列;

2,然后由每一列组成要显示的每一行;

3,给每一行增加换行后拼接成一个正向显示的字符串;

4,将拼接后的字符串直接赋值给UILabel(还是按照从左往右显示)

////// 获得从右向左的竖排文字

 ///UILabel空间,主要用于获取字号和行间距 

 ///原始字符串 

 ///限定的文本高度 ///

public static string GetVerticalBeginFromRight(UILabel label, string str, int heightLim, string spaceXStr) { 

 string retStr = string.Empty;

 if (null == label || str.Equals(string.Empty)) { return ""; } 

 int fontSize = label.fontSize;

 int spacingY = label.spacingY; //首先计算能够有多少列 int lineNum = heightLim/(fontSize + spacingY);

 int column = (int)Mathf.Ceil( (float)str.Length / lineNum ); //Debug.LogError("================lineNum:" + lineNum + "==column:" + column); ListcolStrs = new List(column);

            int lastListIndex = 0;

            int listIndex = 0;

            for ( int i = 0;i < str.Length;i++)

            {

                listIndex = i / lineNum;

                if(listIndex > lastListIndex)

                {

                    string colStr = str.Substring(lastListIndex * lineNum, lastListIndex * lineNum + lineNum > str.Length ? str.Length : lineNum);

                    colStrs.Add(colStr);

                    //Debug.LogError("================lastListIndex:"+ lastListIndex + "==colStrs[lastListIndex]:" + colStrs[lastListIndex]);

                }

                lastListIndex = listIndex;

            }

            string nextColStr = str.Substring(listIndex * lineNum, listIndex * lineNum + lineNum > str.Length ? str.Length - listIndex * lineNum : lineNum);

            colStrs.Add(nextColStr);

            //Debug.LogError("================listIndex:" + listIndex + "==colStrs[listIndex]:" + colStrs[listIndex]);

            //反转colStrs

            colStrs.Reverse();

            //拼接从左向右的换行字符串

            for( int i = 0;i < lineNum;i++)

            {

                //获取每一列中的字符

                string tempStr = string.Empty;

                for ( int m = 0;m < column; m++)

                {

                    string lineChar = colStrs[m].Length > i ? colStrs[m].Substring(i, 1) : GenBlank(CaculateBlankNeed(fontSize, fontSize));

                    //获得符号的宽度

                    int charW = GetTextPrintedSize(lineChar, fontSize);

                    if( charW >= fontSize)

                    {

                        tempStr += (spaceXStr + lineChar);

                    }

                    else

                    {

                        string blank = GenBlank(CaculateBlankNeed(fontSize - charW, fontSize));

                        tempStr += (blank + spaceXStr + lineChar);

                    }

                }

                retStr += tempStr + '\n';

            }

            //Debug.LogError("=================retStr:\n" + retStr);

            label.text = retStr;

            return retStr;

        }

相关文章

  • NGUI文本由右向左竖排显示

    思路: 1,将要显示的文本由前向后拆分为若干列; 2,然后由每一列组成要显示的每一行; 3,给每一行增加换行后拼接...

  • UIlabel详解

    UIlabel是NGUI的基础组件之一,用来显示文本区域。创建一个UILabel,会有一个默认文本“New Lab...

  • CorelDRAW如何设置竖排文字

    很多同学反映,在CorelDRAW中找不到竖排文本工具在哪,或者在设置竖排文本的时候,遇到数字和字母,竖排文字就会...

  • NGUI-UILabel源码解析

    UILabel1.1 概述UILabel是NGUI中用于文字显示的组件,支持图文显示,富文本等功能。阅读本文前请熟...

  • 文艺气质的竖排文本控件来啦

    PlumbTextView PlumbTextView是一个竖排列的文本控件。你可以很容易使用它定义多种竖排文本风...

  • NRD Studio关系图谱中节点名称和描述显示竖排文字

    NRD Studio绘制的关系图谱,节点名称和描述信息显示竖排文字均可通过文本换行功能实现。 打开【编辑节点】面板...

  • 竖排显示文字

  • 【Excel篇】单元格文字“竖排”

    工作中,单元格文本内容需要折行竖排显示,你是否还在“Alt+Enter”诸葛文字折行?如何快速实现,下面带来快捷实...

  • 2018-12-10

    label 文本竖排 仅限汉字 .h #import NS_ASSUME_NONNULL_BEGIN @inter...

  • 不知道的知识点。

    1.如何对NGUI的文本加下划线? UILable控件可以添加富文本格式,原因在于他有BBcode富文本编辑器 我...

网友评论

      本文标题:NGUI文本由右向左竖排显示

      本文链接:https://www.haomeiwen.com/subject/czchkftx.html