开发
API

CanvasContext.setLineCap

基础库 1.0.0 开始支持本方法。

设置线条的端点样式。

语法

CanvasContext.setLineCap(lineCap)

参数说明

参数类型默认值必填说明最低支持版本
lineCapstring端点样式1.0.0

lineCap 合法值

说明最低支持版本
butt向线条的两端添加平直的边缘1.0.0
round向线条的两端添加平直的边缘1.0.0
square向线条的两端添加平直的边缘1.0.0

返回值

代码示例

<!-- index.ttml -->
箭头样式示例,样式顺序:
<block tt:for="{{lineJoinTypes}}">
  <view>{{item}}</view>
</block>

<canvas canvas-id="myCanvas"></canvas>
// index.js
Page({
  data: {
    lineJoinTypes: ["bevel", "round", "miter"],
  },
  onLoad: function (options) {
    const canvasCtx = tt.createCanvasContext("myCanvas");

    canvasCtx.beginPath();
    canvasCtx.setLineJoin("bevel");
    canvasCtx.setLineWidth(10);
    canvasCtx.moveTo(50, 10);
    canvasCtx.lineTo(140, 50);
    canvasCtx.lineTo(50, 90);
    canvasCtx.stroke();

    canvasCtx.beginPath();
    canvasCtx.setLineJoin("round");
    canvasCtx.setLineWidth(10);
    canvasCtx.moveTo(90, 10);
    canvasCtx.lineTo(180, 50);
    canvasCtx.lineTo(90, 90);
    canvasCtx.stroke();

    canvasCtx.beginPath();
    canvasCtx.setLineJoin("miter");
    canvasCtx.setLineWidth(10);
    canvasCtx.moveTo(130, 10);
    canvasCtx.lineTo(220, 50);
    canvasCtx.lineTo(130, 90);
    canvasCtx.stroke();

    canvasCtx.draw();
  },
});

Bug & Tip

点击纠错
评价此篇文档