微信小程序API·setTextBaseline(設(shè)置文字水平對齊)

2022-05-09 16:57 更新

微信小程序 canvas接口和方法繪圖接口和方法

canvasContext.setTextBaseline

基礎(chǔ)庫 1.4.0 開始支持,低版本需做兼容處理

定義

用于設(shè)置文字的水平對齊

參數(shù)

參數(shù)類型定義
textBaselineString可選值 '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()


微信小程序 canvas接口和方法繪圖接口和方法

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號