全局UI方法-弹窗五-时间滑动选择器弹窗(TimePickerDialog)

1、描述

        以24小时的时间区间创建时间滑动选择器,展示在弹窗上。

2、接口

        TimePickerDialog.show(options?: TimePickerDialogOptions)

3、TimePickerDialogOptions

参数名

参数类型

必填

参数描述

selected

Date

设置当前选中的时间。

默认值:当前系统时间

userMilitaryTmeboolean展示时间是否为24小时制,默认为12小时制。默认值:false。
onAccept(value:TimePickerResult) => void点击弹窗中的“确定”按钮时触发该回调。
onCancel() => void点击弹窗中的“取消”按钮时触发该回调。
onChange(value:TimePickerResult) => void滑动弹窗中的选择器使当前选中时间改变时触发该回调。

4、TimePickerResult对象说明

返回值为24小时制时间。

名称

参数类型

描述

hour

number

选中时间的时。

取值范围:[0-23]

minute

number

选中时间的分。

取值范围:[0-59]

5、示例

@Entry
@Component
struct TimePickerDialogPage {
  @State message: string = '定义时间滑动选择器弹窗'

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(20)
          .fontWeight(FontWeight.Bold)
          .width("96%")
          .margin({ top: 12 })

        Button("TimePickerDialog 12 Hour")
          .width("96%")
          .fontSize(20)
          .margin({ top: 12 })
          .onClick(() => {
            TimePickerDialog.show({
              onAccept: (result: TimePickerResult) => {
                console.info("TimePickerDialog Default onAccept result = " + JSON.stringify(result));
              },
              onCancel: () => {
                console.info("TimePickerDialog Default onCancel");
              },
              onChange: (result: TimePickerResult) => {
                console.info("TimePickerDialog Default onChange result = " + JSON.stringify(result));
              }
            })
          })

        Button("TimePickerDialog 24 Hour")
          .width("96%")
          .fontSize(20)
          .margin({ top: 12 })
          .onClick(() => {
            TimePickerDialog.show({
              selected: new Date("2024-01-20T20:30:00"),
              useMilitaryTime: true,
              onAccept: (result: TimePickerResult) => {
                console.info("TimePickerDialog Default onAccept result = " + JSON.stringify(result));
              },
              onCancel: () => {
                console.info("TimePickerDialog Default onCancel");
              },
              onChange: (result: TimePickerResult) => {
                console.info("TimePickerDialog Default onChange result = " + JSON.stringify(result));
              }
            })
          })

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

6、效果图

  • 10
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yyxhzdm

你的鼓励是我创作的最大动力!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值