CanvasContext.setTextBaseline

解释:用于设置文字的水平对齐。

方法参数

StringtextBaseline

textBaseline参数说明 :有效值 'top'、'bottom'、'middle'、'normal' 。

示例

在开发者工具中预览效果

扫码体验

CanvasContext.setTextBaseline - 图1请使用百度APP扫码

图片示例

CanvasContext.setTextBaseline - 图2

CanvasContext.setTextBaseline - 图3

CanvasContext.setTextBaseline - 图4

代码示例

  1. const canvasContext = swan.createCanvasContext('myCanvas');
  2. canvasContext.setStrokeStyle('red');
  3. canvasContext.moveTo(5, 75);
  4. canvasContext.lineTo(295, 75);
  5. canvasContext.stroke();
  6. canvasContext.setFontSize(20);
  7. canvasContext.setTextBaseline('top');
  8. canvasContext.fillText('top', 5, 75);
  9. canvasContext.setTextBaseline('middle');
  10. canvasContext.fillText('middle', 50, 75);
  11. canvasContext.setTextBaseline('bottom');
  12. canvasContext.fillText('bottom', 120, 75);
  13. canvasContext.setTextBaseline('normal');
  14. canvasContext.fillText('normal', 200, 75);
  15. canvasContext.draw();