May 19, 2021 WeChat Mini Program Development Document
Drawing interfaces and methods
Base library 1.4.0 starts to support, and low versions need to be compatible
Used to set the horizontal alignment of text
Parameters | Type | Defined |
---|---|---|
textBaseline | String | Optional values 'top', 'bottom', 'middle', 'normal' |
const ctx = wx.createCanvasContext('myCanvas')
ctx.setStrokeStyle('red')
ctx.moveTo(5, 75)
ctx.lineTo(295, 75)
ctx.stroke()
ctx.setFontSize(20)
ctx.setTextBaseline('top')
ctx.fillText('top', 5, 75)
ctx.setTextBaseline('middle')
ctx.fillText('middle', 50, 75)
ctx.setTextBaseline('bottom')
ctx.fillText('bottom', 120, 75)
ctx.setTextBaseline('normal')
ctx.fillText('normal', 200, 75)
ctx.draw()