Canvas中可以使用arc绘制隐藏下半部分白色区域边缘圆角this.context.lineCap = ‘round’,渐变圆弧createLinearGradient// xxx.ets @Entry @Component struct Arc { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Canvas(this.context) .width('100%') .height('100%') .backgroundColor('#ffffff') .onReady(() =>{ this.context.beginPath() this.context.lineWidth = 10 let grad = this.context.createLinearGradient(50,0, 300,100) grad.addColorStop(0.0, '#ff0000') grad.addColorStop(0.2, '#ffff00') grad.addColorStop(0.5, '#00ff00') this.context.strokeStyle = grad this.context.lineCap = 'round' this.context.arc(100, 75, 50, 3.14, 0) this.context.stroke() }) } .width('100%') .height('100%') } }参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-canvasrenderingcontext2d-V5\#arc
Canvas中可以使用arc绘制隐藏下半部分白色区域
边缘圆角this.context.lineCap = ‘round’,
渐变圆弧createLinearGradient
参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-canvasrenderingcontext2d-V5\#arc