用户可快速集成各类选择器到应用中,该项目提供时间、城市、自定义等多种选择器,支持分隔符、文本样式等属性自定义,满足多样化选择交互需求。
| Files | Last commit | Last update |
|---|---|---|
| 9 months ago | ||
| 9 months ago | ||
| 2 years ago | ||
| 5 months ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 9 months ago | ||
| 4 years ago | ||
| 3 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 2 years ago | ||
| 3 years ago | ||
| 2 years ago | ||
| 2 years ago | ||
| 9 months ago |
PickerView
Overview
PickerView implements a time picker that is capable of time selection, locale selection, divider setting, and text size and color setting.
Display Effects
Time picker:

Time picker (switch between calendars):

Time picker (year, month, day, hour, minute, and second):

Circle divider picker:

City picker (province and city):

Custom picker:

Card picker:

City picker (province, city, and district):

How to Install
ohpm install @ohos/pickerview --save
For details, see Installing an OpenHarmony HAR.
How to Use
The usage of different pickers is similar. The following uses the time picker as an example.
- Initialization: Instantiate scroller and the corresponding ShowTimePickerComponent.Model object.
private scroller: Scroller = new Scroller()
@State showTimeData: ShowTimePickerComponent.Model = new ShowTimePickerComponent.Model();
- Attribute setting: Set UI attributes through the Model class object to define the required style. You can also add required callbacks.
aboutToAppear() {
this.showTimeData
.setDividerLineStroke(2)
.setDividerLineColor(Color.Black)
.setFontSize(20)
.setFontColor(Color.Red)
.setConfirmButtonFont ("OK")
.setCancelButtonFont ("Cancel")
.setCancelButtonColor(Color.Red)
.setConfirmButtonColor(Color.Black)
.setTitleFontSize(20)
.setTitleFontColor(Color.Black)
.setPickerSpace(20)
.setButtonBackgroundColor("#DCDCDC")
.setYearRangeStart(2001)
.setYearRangeEnd(2050)
.setDefaultSelection([2005, 5, 11])
.setDividerType(DividerType.CIRCLE)
.setLineSpacingMultiplier(40)
.withClick((event: ClickEvent) => {
this.showTimeData.withText("clicked " + this.count++ + " times");
});
- UI drawing: Invoke the object constructor to pass the instantiated object.
build() {
Stack() {
Scroll(this.scroller) {
Column() {
ShowTimePickerComponent({model: this.showTimeData})
}
}
}
}
Available APIs
@State showTimeData: ShowTimePickerComponent.Model = new ShowTimePickerComponent.Model();
- Sets the width of the divider line. this.showTimeData.setDividerLineStroke(2)
- Sets the color of the divider line. this.showTimeData.setDividerLineColor(Color.Black)
- Sets the text size. this.showTimeData.setFontSize(20)
- Sets the text color. this.showTimeData.setFontColor(Color.Red)
- Sets the text of the OK button. this.showTimeData.setConfirmButtonFont ("OK")
- Sets the text of the Cancel button. this.showTimeData.setCancelButtonFont ("Cancel")
- Sets the text color of the Cancel button. this.showTimeData.setCancelButtonColor(Color.Red)
- Sets the text color of the OK button. this.showTimeData.setConfirmButtonColor(Color.Black)
- Sets the text size of the title, OK button, and Cancel button. this.showTimeData.setTitleFontSize(20)
- Sets the text color of the title. this.showTimeData.setTitleFontColor(Color.Black)
- Sets the spacing between picker pages. this.showTimeData.setPickerSpace(20)
- Sets the background color of a button. this.showTimeData.setButtonBackgroundColor("#7CDCDC")
- Sets the start time. this.showTimeData.setYearRangeStart(2001)
- Sets the end time. this.showTimeData.setYearRangeEnd(2050)
- Sets the divider type. this.showTimeData.setDividerType(DividerType.CIRCLE)
- Sets the spacing. this.showTimeData.setLineSpacingMultiplier(40)
Constraints
PickerView has been verified in the following versions:
- DevEco Studio: 4.1 Canary (4.1.3.317), OpenHarmony SDK: API11 (4.1.0.36)
- IDE: DevEco Studio Next, Developer Beta1(5.0.3.121), SDK: API12 (5.0.0.16)
Directory Structure
|---- pickerview
| |---- entry # Sample code
| |---- pickerview # PickerView library
| |---- src
|----main
|----ets
|----components
|----common
|----AreaDataPickerViewLib.ets # AreaDataParseSample picker
|----CardModel.ets # Card data generation class
|----CardPickerComponent.ets # Card picker
|----ChinaDateModel.ets # Time entity class.
|----CircleDividerViewLib.ets # Circle divider
|----CityPickerComponent.ets # City picker
|----Constant.ets # Constants
|----CustomizeModel.ets # Custom entities
|----CustomizePickerComponent.ets # Custom pickers
|----HourSecondMinuteComponent.ets # Time picker (hour and minute)
|----HourSecondMinuteModel.ets # Time picker (hour, minute, and second)
|----LunarCalendar.ets # Lunar calendar
|----LunarTimeUtil.ets # Switch between lunar calendar and solar calendar
|----PickerData.ets # Picker data
|----PickerModel.ets # Picker models
|----Province.ets # Province, city, and district data
|----ShowTimePickerViewLib.ets # Time picker views
|----ShowToast.ets # Dialog box
|----SolarCalendar.ets # Solar calendar
|----TimePickerComponent.ets # Time picker
|----YearReachSecondComponent.ets # Time picker (year, month, day, hour, minute, and second)
| |---- README_EN.md # Readme
About obfuscation
- Code obfuscation, please seeCode Obfuscation
- If you want the PickerView library not to be obfuscated during code obfuscation, you need to add corresponding exclusion rules in the obfuscation rule configuration file obfuscation-rules.txt:
-keep
./oh_modules/@ohos/pickerview
How to Contribute
If you find any problem when using PickerView, submit an Issue or PR to us.
License
This project is licensed under Apache License 2.0.
Introduction
用户可快速集成各类选择器到应用中,该项目提供时间、城市、自定义等多种选择器,支持分隔符、文本样式等属性自定义,满足多样化选择交互需求。
Customize your domain