@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一样的效果