# Object CanvasContext.measureText(string text)
Start from base library version 1.9.90. Please remaining backward compatible.
with Promise style call: Not supported
Mini Program plugin: Support
Measure text size information. Currently only the text width is returned. Synchronization interface.
# parameter
# string text
Text to measure
# Return value
# Object
attribute | type | Introductions |
---|---|---|
width | number | Width of text |
# sample code
const ctx = wx.createCanvasContext('myCanvas')
ctx.font = 'italic bold 20px cursive'
const metrics = ctx.measureText('Hello World')
console.log(metrics.width)