HarmonyOS-5(style样式)

@Styles 装饰器  装饰公共的样式

@Styles function  setStyle(){
  .width('90%').height(140)
  .borderRadius(10)
  .backgroundColor("#8000FF00")
  .border({width:1,color:"#333333"})
}

使用:

@Builder  ItemCard(item:ItemBean){
  Row(){
    Image(item.image).height(100).width(50).objectFit(ImageFit.Contain).margin({
      left:20
    })
    Column(){
      Text(item.name).fontSize(20).fontColor($r('app.color.color_333333'))
      Text("¥"+item.price).fontSize(20).fontColor($r('app.color.color_FF0000'))
    }.margin({left:30})
  }.alignItems(VerticalAlign.Center).justifyContent(FlexAlign.Start)
  .setStyle()
}

但是style装饰器封装的属性只能是公共的属性

假如你要用textview的一些特有属性得用,这个有一个区别就是 @Extend装饰器只能用于全局的方法,不能用于组件内方法

@Extend(Text) function setTextstyle(){
  .fontSize(20).fontColor($r('app.color.color_333333'))
}

设置背景拉伸图,和.9一样的效果

鸿蒙开发进阶(HarmonyOS )ArkUI实现9图的拉伸能力场景_鸿蒙加载.9图-优快云博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值