当前位置:K88软件开发文章中心编程全书微信小程序 → 文章内容

微信小程序API·setTextBaseline(设置文字水平对齐)

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-15 15:00:57

由 youj 创建, 最后一次修改 2017-08-16 绘图接口和方法canvasContext.setTextBaseline基础库 1.4.0 开始支持,低版本需做兼容处理定义用于设置文字的水平对齐参数参数类型定义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()绘图接口和方法

微信小程序API·setTextBaseline(设置文字水平对齐)