Skip to content

Caliper 卡尺

介绍

用于选择某个范围内的值。

引入

ts
import { IBestCaliper } from "@ibestservices/ibest-ui-v2"

代码演示

基础用法

基础用法

点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
  @Local value: number = 6
  build() {
    Column({space: 14}){
      Text(this.value.toString())
      IBestCaliper({
        value: this.value!!
      })
    }.alignItems(HorizontalAlign.Start)
  }
}

设置开始结尾数

设置开始结尾数

点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
  @Local value: number = 6
  build() {
    Column({space: 14}){
      Text(this.value.toString())
      IBestCaliper({
        value: this.value!!,
        startNum: 50,
        endNum: 200
      })
    }.alignItems(HorizontalAlign.Start)
  }
}

自定义刻度

自定义刻度

点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
  @Local value: number = 0
  @Local value1: number = 0
  build() {
    Column({space: 14}){
      Text(this.value.toString())
      IBestCaliper({
        value: this.value!!,
        scaleSize: 2
      })
      Text(this.value1.toString())
      IBestCaliper({
        value: this.value1!!,
        scales: 5,
        scaleSize: 2
      })
    }.alignItems(HorizontalAlign.Start)
  }
}

自定义样式

自定义样式

点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
  @Local value: number = 0
  build() {
    Column({space: 14}){
      Text(this.value.toString())
      IBestCaliper({
        value: this.value!!,
        bgColor: "#d8e9f6",
        fontColor: "#038cfd",
        bigScaleHeight: 50,
        smallScaleHeight: 40,
        activeScaleColor: "red",
        activeFontWeight: FontWeight.Bold
      })
    }.alignItems(HorizontalAlign.Start)
  }
}

刻度对齐方式

刻度对齐方式

点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
  @Local value: number = 0
  build() {
    Column({space: 14}){
      Text(this.value.toString())
      IBestCaliper({
        value: this.value!!,
        scaleAlign: "center"
      })
      IBestCaliper({
        value: this.value!!,
        scaleAlign: "bottom"
      })
    }.alignItems(HorizontalAlign.Start)
  }
}

API

@Props

参数说明类型默认值
value绑定值, 支持双向绑定number''
scales大刻度之间划分的小刻度数量number10
scaleSize小刻度代表数值number1
startNum开始刻度值number0
endNum结束刻度值number100
bgColor背景颜色ResourceColor''
scaleColor刻度线颜色ResourceColor#969799
activeScaleColor选中刻度线颜色ResourceColor#1989fa
scaleAlign刻度线对齐方式, 可选值 topcenterbottomstringtop
fontSize刻度值字体大小number14
fontColor刻度值字体颜色ResourceColor#1989fa
bigScaleWidth大刻度线宽度string | number1
bigScaleHeight大刻度线高度string | number30
smallScaleWidth小刻度线宽度string | number1
smallScaleHeight小刻度线高度string | number20
activeScaleWidth选中刻度线宽度string | number3
activeFontWeight选中刻度文字字重string | number| FontWeightNormal
scaleSpace刻度线间距string | number10

Events

事件名说明事件类型
onChange刻度变化回调(value: number) => void

主题定制

组件提供了下列颜色变量,可用于自定义深色/浅色模式样式,使用方法请参考 颜色模式 章节,如需要其它颜色变量可提 issue

名称描述默认值
ibest_caliper_scale_color刻度线颜色#969799