HarmonyOS【ArkUI组件--Button】

1.Button基本使用

2. 通过按钮实现图片放大缩小

在此博客的基础上继续编写:

HarmonyOS【ArkUI组件--TextInput】-CSDN博客

①关键代码如下:

②完整代码如下:

javascript 复制代码
import font from '@ohos.font'
@Entry
@Component
struct Index {
  @State imageWidth:number= 30

  build() {
    Row() {
      Column() {

        Image($r('app.media.app_icon'))
          .width(this.imageWidth)
          .interpolation(ImageInterpolation.High)
        Text($r('app.string.width_label'))
          .fontSize(20)
          .fontWeight(FontWeight.Bold)
        TextInput({text:this.imageWidth.toFixed(0)})
          .width(150)
          .backgroundColor('#36D')
          .type(InputType.Number)
          .onChange(value => {
            this.imageWidth=parseInt(value)
          })
        Button('缩小')
          .width(80)
          .fontSize(20)
          .onClick(()=>{
            if(this.imageWidth>=10){
              this.imageWidth-=10
            }
          })
        Button('放大')
          .width(80)
          .fontSize(20)
          .onClick(()=>{
            if(this.imageWidth<300){
              this.imageWidth+=10
            }
          })
      }

      .width('100%')
    }
    .height('100%')
  }
}

③效果如下:

相关推荐
别说我什么都不会13 小时前
鸿蒙(HarmonyOS)性能优化实战-页面布局检查器ArkUI Inspector
性能优化·harmonyos·arkui
二流小码农15 小时前
鸿蒙开发:wrapBuilder传递参数
android·ios·harmonyos
别说我什么都不会15 小时前
鸿蒙(HarmonyOS)性能优化实战-应用性能分析工具CPU Profiler使用指南
性能优化·harmonyos
png16 小时前
从零开始纯血鸿蒙天气预报-主界面(1)
harmonyos·arkui
城中的雾16 小时前
鸿蒙开发者必看:如何用一行命令搞定HSP/HAP文件安装?
harmonyos
23zhgjx-zgx16 小时前
OSPF:虚链路
网络·tcp/ip·华为·智能路由器·ensp
Georgewu18 小时前
【HarmonyOS Next】鸿蒙应用弹框和提示气泡详解(一)
前端·华为·harmonyos
今阳18 小时前
鸿蒙开发笔记-11-LazyForEach 数据懒加载
android·华为·harmonyos
坚果的博客19 小时前
鸿蒙版Flutter快递查询助手
flutter·华为·harmonyos
轻口味19 小时前
【每日学点HarmonyOS Next知识】状态栏控制、片段按钮点击回调、绘制组件、取消按钮与输入框对齐、父调子组件方法
pytorch·华为·harmonyos·harmonyosnext