cc.Class({
extends: cc.Component,
properties: {
label: {
default: null,
type: cc.Label
},
// defaults, set visually when attaching this script to the Canvas
text: 'Hello, World!'
},
// use this for initialization
start: function () {
alert(this.label.node.width); // 146
this.label.string = '这是一段测试用的长文本';
alert(this.label.node.width); // 146 未变更
setTimeout(() => {
alert(this.label.node.width); // 660 变更
})
}
});
其中Label 的 Overflow设置的NONE