CanvasContext.setLineDash
2020-08-26 16:40 更新
解释:设置线条虚线样式的间距和长度。
方法参数
参数名 | 属性 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
pattern | Array | 是 | 一组描述交替绘制线段和间距(坐标空间单位)长度的数字 | |
offset | Number | 是 | 虚线偏移量 |
示例
图片示例
代码示例 1:基础用法
<canvas canvas-id="myCanvas" class="myCanvas" />
Page({
onLoad() {
const canvasContext = swan.createCanvasContext('myCanvas');
canvasContext.setLineDash([10, 20], 5);
canvasContext.beginPath();
canvasContext.moveTo(0,100);
canvasContext.lineTo(400, 100);
canvasContext.stroke();
canvasContext.draw();
}
});
代码示例 2
<canvas canvas-id="myCanvas" class="myCanvas" />
Page({
onLoad() {
const canvasContext = swan.createCanvasContext('myCanvas');
canvasContext.setLineDash([10, 20], 5);
canvasContext.beginPath();
canvasContext.moveTo(0,100);
canvasContext.lineTo(400, 100);
canvasContext.stroke();
canvasContext.setLineDash([5, 10, 5], 5);
canvasContext.beginPath();
canvasContext.moveTo(0, 200);
canvasContext.lineTo(400, 200);
canvasContext.stroke();
canvasContext.draw();
}
});
以上内容是否对您有帮助:
更多建议: