JMToastItem.js 837 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * Toast单元格
  3. */
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. label: cc.RichText,
  8. msg: {
  9. multiline: true,
  10. type: cc.String,
  11. get () {
  12. return this._msg;
  13. },
  14. set (value) {
  15. if (this._msg !== value) {
  16. this._msg = value;
  17. this.updateMsg();
  18. }
  19. }
  20. },
  21. _msg: ''
  22. },
  23. /**
  24. * 更新 Toast 文本
  25. *
  26. * @author Pyden
  27. * @date 2019-03-22
  28. */
  29. updateMsg () {
  30. if (this.label) {
  31. this.label.string = this.msg;
  32. }
  33. this.node.width = this.label.node.width + 100; // 左右各50px边距
  34. this.node.height = this.label.node.height + 30; // 上下各15px边距
  35. }
  36. });