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

③效果如下:

相关推荐
全栈开发圈14 小时前
干货分享|鸿蒙6开发从0到App上线
华为·harmonyos
奔跑的露西ly15 小时前
【HarmonyOS NEXT】ArkUI实现「单格单字符+下划线」手机号/验证码输入框
ui·华为·harmonyos·鸿蒙
木斯佳15 小时前
HarmonyOS实战(人机交互篇):当ToB系统开始“思考”,我们该设计什么样的界面?
华为·人机交互·harmonyos
夜雨声烦丿16 小时前
Flutter 框架跨平台鸿蒙开发 - 中英互译助手 - 完整开发教程
flutter·华为·harmonyos
No Silver Bullet17 小时前
HarmonyOS NEXT开发进阶(二十一):compatibleSdkVersion 和 targetSdkVersion配置项详解
华为·harmonyos
小白阿龙18 小时前
鸿蒙+flutter 跨平台开发——图像编解码与水印嵌入技术实战
flutter·华为·harmonyos·鸿蒙
哈哈你是真的厉害18 小时前
基础入门 React Native 鸿蒙跨平台开发:ActionSheet 动作面板
react native·react.js·harmonyos
夜雨声烦丿18 小时前
Flutter 框架跨平台鸿蒙开发 - 成语词典 - 完整开发教程
flutter·华为·harmonyos
奔跑的露西ly18 小时前
【HarmonyOS NEXT】踩坑记录:00306046 Specification Limit Violation
华为·harmonyos
小白阿龙19 小时前
鸿蒙+flutter 跨平台开发——基于日历视图的生理周期计算逻辑
flutter·华为·harmonyos·鸿蒙