W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
漸變對象。
從 API Version 8 開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨標(biāo)記該內(nèi)容的起始版本。
addColorStop(offset: number, color: string): void
設(shè)置漸變斷點值,包括偏移和顏色。
從API version 9開始,該接口支持在ArkTS卡片中使用。
參數(shù):
參數(shù) | 類型 | 必填 | 默認(rèn)值 | 描述 |
---|---|---|---|---|
offset | number | 是 | 0 | 設(shè)置漸變點距離起點的位置占總體長度的比例,范圍為0到1。 |
color | string | 是 | '#ffffff' | 設(shè)置漸變的顏色。顏色格式參考ResourceColor中string類型說明。 |
示例:
- // xxx.ets
- @Entry
- @Component
- struct Page45 {
- 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('#ffff00')
- .onReady(() => {
- var grad = this.context.createLinearGradient(50, 0, 300, 100)
- grad.addColorStop(0.0, '#ff0000')
- grad.addColorStop(0.5, '#ffffff')
- grad.addColorStop(1.0, '#00ff00')
- this.context.fillStyle = grad
- this.context.fillRect(0, 0, 400, 400)
- })
- }
- .width('100%')
- .height('100%')
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: