Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat program API setTextAlign (for setting the alignment of text)


May 19, 2021 WeChat Mini Program Development Document


Table of contents


WeChat program API setTextAlign (for setting the alignment of text) Drawing interfaces and methods

canvasContext.setTextAlign


Base library version 1.1.0 starts to support, and low versions need to be compatible

Defined

Used to set the alignment of text

Parameters

Parameters Type Defined
align String Optional values 'left', 'center', 'right'

Example code:

const ctx = wx.createCanvasContext('myCanvas')

ctx.setStrokeStyle('red')
ctx.moveTo(150, 20)
ctx.lineTo(150, 170)
ctx.stroke()

ctx.setFontSize(15)
ctx.setTextAlign('left')
ctx.fillText('textAlign=left', 150, 60)

ctx.setTextAlign('center')
ctx.fillText('textAlign=center', 150, 80)

ctx.setTextAlign('right')
ctx.fillText('textAlign=right', 150, 100)

ctx.draw()

WeChat program API setTextAlign (for setting the alignment of text)


WeChat program API setTextAlign (for setting the alignment of text) Drawing interfaces and methods