猫史档案馆


cocos·Label

用户:Banana君Banana君查看:0 回复:1 评论:0 创建时间:2019-01-05T20:14:53


center_image

 

官网属性文档:https://docs.cocos.com/creator/manual/zh/components/label.html

 

cc.Label相关技巧:

(1)动态创建cc.Label : var node = new cc.Node('text'); node.addComonpnet(cc.Label);

(2)  设置文本内容:node.getComponent(cc.Label).string = 'test'; 设置大小:node.getComponent(cc.Label).fontSize = 30 文本对齐:参考creator中

(3)  如何动态获取文本的宽度: node.getComponent(cc.Label).string = 'test'; var getWidth = node.width;这样即可获得宽度;注意事项:要让node所在父节点active =true,即让js脚本调用onload函数之后,才能正确获取with;

(4) 文本长度超出creator中设定长度时不显示:node.getComponent(cc.Label).overFlow = cc.Label.Overflow.CLAMP 还有其它几种模式暂时没用到后续研究,这里说下含义,NONE(无样式)、CLAMP(截断)、SHRINK(自动缩小文字以适应大小)、RESIZE_HEIGHT(自增长高度)


回复

上一页1 页 / 共 1下一页
一个新手一个新手

大佬,请收下我的膝盖

点赞0


评论