如何使用Styles动态的去修改组件当中的样式,比如要封装一个导航栏组件,使用该组件时传入对应的样式

HarmonyOS 如何使用Styles动态的去修改组件当中的样式,比如要封装一个导航栏组件,使用该组件时传入对应的样式。

HarmonyOS
2024-10-16 09:07:27
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

参考以下代码示例:

@Entry  
@Component  
export struct ImageRotationPage {  
  @State rotateValue: number = 0;  
  fancyParams: FancyParam = new FancyParam();  
  @Styles globalFancy() {  
  .width(this.fancyParams.width)  
  .height(this.fancyParams.height)  
  .backgroundColor(Color.Pink)  
}  
  aboutToAppear(): void {  
     this.fancyParams.width = 100  
    this.fancyParams.height = 50  
  }  
  @Builder ShowToast() {  
    Column() {  
      Image($r("app.media.app_icon"))  
        .globalFancy()  
        .margin({bottom: 10})  
        .rotate({ angle: this.rotateValue })  
        .animation({  
          duration: 2000,  
          curve: Curve.Linear,  
          iterations: -1,  
          playMode: PlayMode.Normal  
        })  
        .onComplete(() => {  
          animateTo({ curve: Curve.Linear }, () => {  
            console.log("curves springMotion");  
            this.rotateValue = 360  
          })  
        })  
    }  
  }  
  build() {  
    Column() {  
      this.ShowToast()  
    }  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
分享
微博
QQ
微信
回复
2024-10-16 16:04:59
相关问题
如何实现一个仪表盘样式组件
1086浏览 • 1回复 待解决
是否支持统styles样式封装
820浏览 • 1回复 待解决
如何自定义Video组件控制样式
3612浏览 • 1回复 待解决
HarmonyOS 如何设定tabs组件tabbar样式
1410浏览 • 1回复 待解决
@Extend样式如何组件共享?
2951浏览 • 1回复 待解决
提供一个关于地图组件使用小demo
1510浏览 • 1回复 待解决