May 19, 2021 WeChat Mini Program Development Document
Base library 1.9.90 starts to support, and low versions need to be compatible
Measure text size information and currently only return text width. Synchronize the interface.
Parameters | Type | Description |
---|---|---|
text | String | The text to measure |
Returns the TextMetrics object, structured as follows:
Parameters | Type | Description |
---|---|---|
width | Number | The width of the text |
const ctx = wx.createCanvasContext('myCanvas')
ctx.font = 'italic bold 20px cursive'
const metrics = ctx.measureText('Hello World')
console.log(metrics.width)