ArkTs快速入门

一、声明式UI

声明式UI是一种编写用户界面的范式。

1.1 声明组件

build() {
      Column() {
        Button({type:ButtonType.Circle}){
          Image('src/main/ets/pages/3.png')
            .width(25)
            .height(25)
        }
        .width(50)
        .height(50)
        .backgroundColor(Color.Red)
        .onClick(() =>{
          console.log('删除');
        })
      }
      .width('100%')
      .height('100%')
      .justifyContent(FlexAlign.Center);

  }
}

1.2 自定义组件

使用自定义组件,可以使代码结构更加清晰,并且能提高代码的复用性

@Entry
@Component
struct Index {
  @State message: string = 'Hello World'
  build() {
      Column() {
        RedButton({color:Color.Red}) //给自定义组件传参,必须是一个对象
        .onClick(() =>{
          console.log('删除');
        })
      }
      .width('100%')
      .height('100%')
      .justifyContent(FlexAlign.Center);
  }
}
@Component
struct RedButton {
  color:Color = Color.Black;

  build() {
    Button({type:ButtonType.Circle}){
      Image('src/main/ets/pages/3.png')
        .width(25)
        .height(25)
    }
    .width(50)
    .height(50)
    .backgroundColor(this.color)
  }
}

1.3 渲染控制

1.3.1 条件渲染

条件渲染可根据应用的不同状态渲染不同的UI界面

1.3.2 循环渲染

循环渲染可使用ForEach语句基于一个数组来快速渲染一个组件列表

二、常用组件

2.1 图片

2.1.1图片参数

Image组件的参数类型为string | Resource | media PixeMap

Resource类型:

media PixeMap:

指的是像素位图,其通常是一个二维数组,数组中的每个元素对应着图片中的一个像素,其包含了该像素的颜色等信息。

2.1.2 常用属性

参数有string、number、Resource类型

2.1.3 图片缩放

2.1.4 图片插值

是图像过渡更加平滑

相关推荐

  1. 鸿蒙ArkTS语言快速入门-TS(五)

    2024-04-23 07:28:04       46 阅读
  2. ArkTs基础入门

    2024-04-23 07:28:04       29 阅读
  3. ArkTS语言基础入门学习-鸿蒙开发

    2024-04-23 07:28:04       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-23 07:28:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-23 07:28:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-23 07:28:04       82 阅读
  4. Python语言-面向对象

    2024-04-23 07:28:04       91 阅读

热门阅读

  1. ffmpeg截图(关键帧截图)

    2024-04-23 07:28:04       40 阅读
  2. 开发语言漫谈-erlang

    2024-04-23 07:28:04       44 阅读
  3. 使用 less

    2024-04-23 07:28:04       32 阅读
  4. Tomcat 启动闪退的通用解决方案

    2024-04-23 07:28:04       29 阅读
  5. linux 如何查看Tomcat进程

    2024-04-23 07:28:04       28 阅读
  6. 拖尾渲染器-Unity拖尾渲染器的使用

    2024-04-23 07:28:04       32 阅读
  7. PyTorch如何保存验证集上效果最好的模型

    2024-04-23 07:28:04       36 阅读
  8. react经验12:等待状态更新

    2024-04-23 07:28:04       30 阅读