Files
heros/doc/mvvm/VMLabel.md

34 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## VM Label
### 介绍
VM组件文本监听用于处理 Label 的监听问题。监听watchPath 路径 数值的变动情况变动Label文本内容。使用模板模式还可以将输入的字符串格式化。可以监听多路径来同时在一个label上显示多个数据源的信息。
### 编辑器属性
- `Template Mode` - 多路径模板模式,开启后可以监听多路径,并且可以设置文本模板
- `Watch Path ` - 绑定数值监听路径
- `Watch PathArr` - 绑定数值监听的路径数组 (多路径模板模式开启后出现)
- `Label Type` - 只读属性自动绑定cc.Label 或者 cc.RichText你可以在脚本修改自己定义的Label
### 关于模板解析
使用 {{0}} {{1}} {{2}} 方式设置模板内容设置label 的 String 默认值。在运行时会动态的获取多路径监听的值按数组内index 顺序替换掉 {{index}}。你可以额外添加修饰符号来格式化信息源,比如 {{0:int}} 会将数字内容以整数显示,{{0:time}} 以时间格式显示时间戳 等。
以下是目前支持的格式化内容:
- `int` - 只显示整数部分
- `fix(n)` -显示小数位数
- `kmbt` - 以 K M B T 单位 缩短数字长度
- `per ` - 显示百分比
- `sep` - 以千位分号分割数字
- `limit(n)` - 限制文本字符长度
### 自定义模板格式
所有 文本格式处理 都放在 StringFormat 类中,你可以根据自定义需要修改其中的函数。