当前位置: 首页 > news >正文

鸿蒙开发之统一样式, @Styles 复用样式

只能使用通用样式

@Entry
@Component
struct Test {// 样式 就近原则 即{}之内的优先级更高 @Styles customStyles(){.width(200).height(60).backgroundColor(Color.Red)}build() {Row() {Column({ space: 5 }) {Text("自定义样式").fontSize(30).textAlign(TextAlign.Center).customStyles()Button("Button").customStyles()Image($r("app.media.logo")).customStyles()}.width("100%").alignItems(HorizontalAlign.Center)}.height("100%")}
}@Styles function customStyles() {.width(200).height(60).backgroundColor("#36D")}

在这里插入图片描述
在这里插入图片描述

上面是不可传参数的

@Entry
@Component
struct Test {build() {Row() {Column({ space: 5 }) {Text("自定义样式").customStyles(20,Color.Pink).backgroundColor("#36D").padding(10).borderRadius(30)Text("自定义样式").customStyles(30,Color.Red).backgroundColor("#36D").padding(10).borderRadius(30)Text("自定义样式").customStyles(40,Color.Blue).backgroundColor("#36D").padding(10).borderRadius(30)// Button("Button")// Image($r("app.media.logo")).height(100)}.width("100%").alignItems(HorizontalAlign.Center)}.height("100%")}
}
@Extend(Text) function customStyles(size:number,color:Color){.fontSize(size).fontColor(color)}

在这里插入图片描述

@Entry
@Component
struct Test {build() {Row() {Column({ space: 5 }) {Text("自定义样式").customStyles(20,Color.Pink).backgroundColor("#36D").padding(10).borderRadius(30)Text("自定义样式").customStyles(30,Color.Red).backgroundColor("#36D").padding(10).borderRadius(30)Text("自定义样式").customStyles(40,Color.Blue).backgroundColor("#36D").padding(10).borderRadius(30)Text("自定义样式").textStyles(30,Color.Red).backgroundColor("#36D").padding(10).borderRadius(30)Text("自定义样式").textStyles(40,Color.Blue).backgroundColor("#36D").padding(10).borderRadius(30)Text("自定义样式").textStyles(40,Color.Yellow).backgroundColor("#36D").padding(10).borderRadius(30)// Button("Button")// Image($r("app.media.logo")).height(100)}.width("100%").alignItems(HorizontalAlign.Center)}.height("100%")}
}
@Extend(Text) function customStyles(size:number,color:Color){.fontSize(size).fontColor(color)}@Extend(Text) function textStyles(size:number,color:Color){.customStyles(size,color).fontStyle(FontStyle.Italic).fontWeight(FontWeight.Bold)}

在这里插入图片描述

http://www.lryc.cn/news/265115.html

相关文章:

  • 解决java内存问题
  • 分享5款为你生活带来便捷的小工具
  • 【Java JVM】JVM 分析工具
  • 融资项目——vue之双向数据绑定
  • 『番外篇五』SwiftUI 进阶之如何动态获取任意视图的 tag 和 id 值
  • 姿态识别、目标检测和跟踪的综合应用
  • 数据结构考试测试编程题
  • 力扣每日一题day37[113.路径总和ii]
  • Keras使用sklearn中的交叉验证和网格搜索
  • docker--Prometheus、Grafana、node_exporter的安装配置及Springboot集成Prometheus示例
  • 数据结构和算法笔记2:二分法
  • Mybatis3系列课程8-带参数查询
  • IDEA shorten command line介绍和JAR manifest 导致mybatis找不到接口类处理
  • 泽攸科技SEM台式扫描电子显微镜
  • 华为交换机配置BGP的基本示例
  • 数据分析基础之《numpy(4)—ndarry运算》
  • 分享一个项目——Sambert UI 声音克隆
  • ES6 语法精粹简读
  • uniapp整合echarts(目前性能最优、渲染最快方案)
  • 解决Electron应用中的白屏问题的实用方法
  • 大数据---34.HBase数据结构
  • 【工具使用-有道云笔记】如何在有道云笔记中插入目录
  • 用户管理第2节课-idea 2023.2 后端一删除表,从零开始---【本人】
  • 如何添加jar包到本地Maven项目中
  • 智能优化算法应用:基于学校优化算法3D无线传感器网络(WSN)覆盖优化 - 附代码
  • 【MATLAB第85期】基于MATLAB的2023年智能进化算法/元启发式算法合集(持续更新)
  • [Realtek sdk-3.4.14b]RTL8197FH-VG+RTL8812F WiFi使用功率限制功能使用说明
  • Vue中为什么data属性是一个函数而不是一个对象?(看完就会了)
  • Linux中一些知识积累(持续补充)
  • 内网渗透基础