cocos-html 3.10 修改ccui.Text, ccui.RichText行间距

来源:互联网 发布:tomcat端口被占用 编辑:程序博客网 时间:2024/06/09 22:36

1、修改ccui.RichText行间距

在UIRichText.js中,函数formatRenderers(),中计算各个元素的位置,看下面修改引擎的方法,把lineHeight和contentSize.height的最大值最为行高,并且在设置富文本的时候,设置行高lineHeight;


富文本设置行高的的办法

var lineHeight = richText.lineHeight ? richText.lineHeight : "normal";var fontDef = new cc.FontDefinition({    fillStyle: color,    fontName: gFontName,    fontSize: 20,    fontWeight: boldStr,    lineHeight:lineHeight,})var richElement = new ccui.RichElementText(i, fontDef, 255, String(textStr));
这样就可以修改富文本的行间距了。


2、ccui.Text的设置行间距

ccui.Text真正容纳文本的实际上是cc.LabelTTF,而cc.LabelTTF计算行距又是在CCLabelTTFCanvasRenderCmd.js中执行的,通过cc.LabelTTF.RenderCmd中的_saveStatus()来保存文本的状态,然后在之后的渲染中来渲染,下面就是获取行高的方法,其中的node就是ccui.Text中的_labelRenderer成员变量,这个成员变量是cc.LabelTTF的一个实例。

//lineHeightvar lineHeight = node.getLineHeight();

现在我们要设置ccui.Text中的_labelRenderer的行高

var textNode = new ccui.Text();

var lineHeight = 50;

textNode._labelRenderer.setLineHeight(lineHeight );

由于引擎里面没有直接设置行高的方法,所以只有直接使用_labelRenderer的方法




原创粉丝点击