如何实现组件边缘的颜色渐变?

问题现象

如何实现组件边缘的颜色渐变

image.png

阅读 336
1 个回答

解决措施

可通过通用属性linearGradient来实现组件边缘的颜色渐变效果。

示例代码

// xxx.ets 
@Entry 
@Component 
struct Index { 
  build() { 
    Row() { 
      Column() { 
        Column({ space: 5 }) { 
          Text('linearGradient').fontSize(12).width('90%').fontColor(0xCCCCCC) 
          Row() { 
            Text('This is gradient color.') 
              .textAlign(TextAlign.Center) 
              .width('96%') 
              .height('80%') 
              .borderRadius(30) 
              .linearGradient({ 
                direction: GradientDirection.Left, // 渐变方向 
                repeating: true, // 渐变颜色是否重复 
                colors: [[0xDCDCDC, 0.0], [0xFFFFFF, 1.0]] // 数组末尾元素占比小于1时满足重复着色效果 
              }) 
          } 
          .width('90%') 
          .height(60) 
          .borderRadius(30) 
          .linearGradient({ 
            angle: 90, 
            colors: [[0x87CEEB, 0.0], [0x2E8B57, 1.0]] 
          }) 
          .justifyContent(FlexAlign.Center) 
        } 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进