基础库 1.9.90 开始支持,低版本需做兼容处理
测量文本尺寸信息,目前仅返回文本宽度。同步接口。
参数 | 类型 | 说明 |
---|---|---|
text | string | 要测量的文本 |
返回 textmetrics 对象,结构如下:
参数 | 类型 | 说明 |
---|---|---|
width | number | 文本的宽度 |
const ctx = wx.createcanvascontext('mycanvas')
ctx.font = 'italic bold 20px cursive'
const metrics = ctx.measuretext('hello world')
console.log(metrics.width)