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%')
  }
}

③效果如下:

相关推荐
OH_TPC3 小时前
@ohos/grpc 源码解读(二):四种 RPC 模式的流状态机——EOF、DEFERRED 与 wakeupPipe 的分工
harmonyos
行者-全栈开发7 小时前
【鸿蒙心迹】性能常态化检测——内存 / CPU / 帧率三件套怎么建基线、设门禁(HarmonyOS 7.x)
harmonyos·内存泄漏·cpu占用·ci门禁·性能检测·帧率监控·性能基线
NJPJI_Yang10 小时前
鸿蒙操作系统使用 Image Kit 实现图片解码编辑与压缩保存实战(本文已在AtomGit仓库开源)
华为·开源·harmonyos
程序猿追10 小时前
HarmonyOS 7 剪贴板读写,同一份内容怎样带上纯文本和 HTML
华为·html·harmonyos
程序猿追12 小时前
HarmonyOS 7 HTTP 请求封装,怎样区分 503、超时和解析失败
http·华为·harmonyos
程序猿追21 小时前
HarmonyOS 7 ArkUI 卡片点击分发:点关闭按钮,怎样确保只收起推荐
pytorch·深度学习·harmonyos
默 语1 天前
HarmonyOS7 组件通用事件(四):onSizeChange 尺寸变化事件——同步回调里,别急着改状态
harmonyos
默 语1 天前
HarmonyOS7 通用事件实战:点击、拖拽、焦点、悬停、快捷键与软键盘(附完整案例)
harmonyos
程序猿追1 天前
HarmonyOS 7 阅读页换一套配色后怎样记住上次选择
华为·harmonyos
程序猿追1 天前
HarmonyOS 7 本机书签里,两篇同名文章怎样在重启后各自打开
大数据·数据分析·harmonyos