Label长文本手机上不显示处理longText.zip
Label长文本手机上不显示处理 // Learn cc.Class: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { nodeModule: cc.Node, nodeContainer: cc.Node, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start () { }, // update (dt) {}, setLongText(longText){ // 界限值 const WORDS_COUNT = 100; let str = longText; let left = ''; do{ let index = str.indexOf('\n'); if(index == -1){ break; } left = left + str.substring(0, index); str = str.substring(index); while(str.length > 0 && str[0] == '\n'){ left = left + str[0]; str = str.substring(1); } if(left.length > WORDS_COUNT){ if(left.length >= 1&& left[left.length - 1] == '\n'){ left = left.substring(0, left.length -1); } this.addModule(left); left = ''; } }while(str.length > WORDS_COUNT); if(left != ''){ this.addModule(left); } if(str != ''){ this.addModule(str); } }, addModule(text){ cc.log('##text##', text); let node = cc.instantiate(this.nodeModule); node.active = true; no
文件列表
longText.zip
(预估有个12文件)
longText
.gitignore
2KB
settings
project.json
625B
services.json
7KB
creator.d.ts
866KB
packages
jsconfig.json
280B
project.json
60B
assets
暂无评论