1e41f4b71Sopenharmony_ci# picker-view 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **\<picker-view>** component provides the view that shows an embedded scrollable selector on the screen. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Child Components 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciNot supported 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## Attributes 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 18e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 19e41f4b71Sopenharmony_ci| type | string | text | No| Type of the scrollable selector, which cannot be changed dynamically. Available values are as follows:<br>- **text**: text selector.<br>- **time**: time selector.| 20e41f4b71Sopenharmony_ci| id | string | - | No| Unique ID of the component.| 21e41f4b71Sopenharmony_ci| style | string | - | No| Style declaration of the component.| 22e41f4b71Sopenharmony_ci| class | string | - | No| Style class of the component, which is used to refer to a style table.| 23e41f4b71Sopenharmony_ci| ref | string | - | No| Reference information of child elements, which is registered with the parent component on **$refs**.| 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ciText selector (**type** is **text**) 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 28e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 29e41f4b71Sopenharmony_ci| range | Array | - | No| Value range of the text selector.<br>Use data binding, for example, **range = {{data}}**, to specify the range. Declare the corresponding variable in the JavaScript: **data: ["15", "20", "25"]**.| 30e41f4b71Sopenharmony_ci| selected | string | 0 | No| Default value of the text selector. The value is the index of **range**.| 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ciTime selector (**type** is **time**) 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 35e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 36e41f4b71Sopenharmony_ci| selected | string | 00:00 | No| Default value of the time selector, in the format of HH:mm.<br>| 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci## Events 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ciText selector (**type** is **text**) 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci| Name| Parameter| Description| 44e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 45e41f4b71Sopenharmony_ci| change | { newValue: newValue, newSelected: newSelected } | Triggered when a value is specified for the text selector.| 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ciTime selector (**type** is **time**) 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci| Name| Parameter| Description| 50e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 51e41f4b71Sopenharmony_ci| change | { hour: hour, minute: minute} | Triggered when a value is specified for the time selector. | 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci## Styles 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 57e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 58e41f4b71Sopenharmony_ci| color | <color> | \#808080 | No| Font color of a candidate item.| 59e41f4b71Sopenharmony_ci| font-size | <length> | 30px | No| Font size of a candidate item. The value is of the length type, in pixels.| 60e41f4b71Sopenharmony_ci| selected-color | <color> | \#ffffff | No| Font color of the selected item.| 61e41f4b71Sopenharmony_ci| selected-font-size | <length> | 38px | No| Font size of the selected item. The value is of the length type, in pixels.| 62e41f4b71Sopenharmony_ci| selected-font-family | string | HYQiHei-65S | No| Font type of the selected item.| 63e41f4b71Sopenharmony_ci| font-family | string | HYQiHei-65S | No| Font type of an item.| 64e41f4b71Sopenharmony_ci| width | <length> \| <percentage><sup>5+</sup> | - | No| Component width.<br>If this attribute is not set, the default value **0** is used. | 65e41f4b71Sopenharmony_ci| height | <length> \| <percentage><sup>5+</sup> | - | No| Component height.<br>If this attribute is not set, the default value **0** is used. | 66e41f4b71Sopenharmony_ci| padding | <length> | 0 | No| Shorthand attribute to set the padding for all sides.<br>The attribute can have one to four values:<br>- If you set only one value, it specifies the padding for all the four sides.<br>- If you set two values, the first value specifies the top and bottom padding, and the second value specifies the left and right padding.<br>- If you set three values, the first value specifies the top padding, the second value specifies the left and right padding, and the third value specifies the bottom padding.<br>- If you set four values, they respectively specify the padding for top, right, bottom, and left sides (in clockwise order).| 67e41f4b71Sopenharmony_ci| padding-[left\|top\|right\|bottom] | <length> | 0 | No| Left, top, right, and bottom padding.| 68e41f4b71Sopenharmony_ci| margin | <length> \| <percentage><sup>5+</sup> | 0 | No| Shorthand attribute to set the margin for all sides. The attribute can have one to four values:<br>- If you set only one value, it specifies the margin for all the four sides.<br>- If you set two values, the first value specifies the top and bottom margins, and the second value specifies the left and right margins.<br>- If you set three values, the first value specifies the top margin, the second value specifies the left and right margins, and the third value specifies the bottom margin.<br>- If you set four values, they respectively specify the margin for top, right, bottom, and left sides (in clockwise order).| 69e41f4b71Sopenharmony_ci| margin-[left\|top\|right\|bottom] | <length> \| <percentage><sup>5+</sup> | 0 | No| Left, top, right, and bottom margins.| 70e41f4b71Sopenharmony_ci| border-width | <length> | 0 | No| Shorthand attribute to set the margin for all sides.| 71e41f4b71Sopenharmony_ci| border-color | <color> | black | No| Shorthand attribute to set the color for all borders.| 72e41f4b71Sopenharmony_ci| border-radius | <length> | - | No| Radius of round-corner borders.| 73e41f4b71Sopenharmony_ci| background-color | <color> | - | No| Background color.| 74e41f4b71Sopenharmony_ci| display | string | flex | No| How and whether to display the box containing an element. Available values are as follows:<br>- **flex**: flexible layout<br>- **none**: not rendered| 75e41f4b71Sopenharmony_ci| [left\|top] | <length> \| <percentage><sup>6+</sup> | - | No| Edge of the element.<br>- **left**: left edge position of the element. This attribute defines the offset between the left edge of the margin area of a positioned element and left edge of its containing block.<br>- **top**: top edge position of the element. This attribute defines the offset between the top edge of a positioned element and that of a block included in the element. | 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci## Example 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci```html 82e41f4b71Sopenharmony_ci<!-- xxx.hml --> 83e41f4b71Sopenharmony_ci<div class="container" @swipe="handleSwipe"> 84e41f4b71Sopenharmony_ci <text class="title"> 85e41f4b71Sopenharmony_ci Selected: {{time}} 86e41f4b71Sopenharmony_ci </text> 87e41f4b71Sopenharmony_ci <picker-view class="time-picker" type="time" selected="{{defaultTime}}" @change="handleChange"></picker-view> 88e41f4b71Sopenharmony_ci</div> 89e41f4b71Sopenharmony_ci``` 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci```css 93e41f4b71Sopenharmony_ci/* xxx.css */ 94e41f4b71Sopenharmony_ci.container { 95e41f4b71Sopenharmony_ci flex-direction: column; 96e41f4b71Sopenharmony_ci justify-content: center; 97e41f4b71Sopenharmony_ci align-items: center; 98e41f4b71Sopenharmony_ci left: 0px; 99e41f4b71Sopenharmony_ci top: 0px; 100e41f4b71Sopenharmony_ci width: 454px; 101e41f4b71Sopenharmony_ci height: 454px; 102e41f4b71Sopenharmony_ci} 103e41f4b71Sopenharmony_ci.title { 104e41f4b71Sopenharmony_ci font-size: 30px; 105e41f4b71Sopenharmony_ci text-align: center; 106e41f4b71Sopenharmony_ci} 107e41f4b71Sopenharmony_ci.time-picker { 108e41f4b71Sopenharmony_ci width: 500px; 109e41f4b71Sopenharmony_ci height: 400px; 110e41f4b71Sopenharmony_ci margin-top: 20px; 111e41f4b71Sopenharmony_ci} 112e41f4b71Sopenharmony_ci``` 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci```js 116e41f4b71Sopenharmony_ci/* xxx.js */ 117e41f4b71Sopenharmony_ciexport default { 118e41f4b71Sopenharmony_ci data: { 119e41f4b71Sopenharmony_ci defaultTime: "", 120e41f4b71Sopenharmony_ci time: "", 121e41f4b71Sopenharmony_ci }, 122e41f4b71Sopenharmony_ci onInit() { 123e41f4b71Sopenharmony_ci this.defaultTime = this.now(); 124e41f4b71Sopenharmony_ci }, 125e41f4b71Sopenharmony_ci handleChange(data) { 126e41f4b71Sopenharmony_ci this.time = this.concat(data.hour, data.minute); 127e41f4b71Sopenharmony_ci }, 128e41f4b71Sopenharmony_ci now() { 129e41f4b71Sopenharmony_ci const date = new Date(); 130e41f4b71Sopenharmony_ci const hours = date.getHours(); 131e41f4b71Sopenharmony_ci const minutes = date.getMinutes(); 132e41f4b71Sopenharmony_ci return this.concat(hours, minutes); 133e41f4b71Sopenharmony_ci }, 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci fill(value) { 136e41f4b71Sopenharmony_ci return (value > 9 ? "" : "0") + value; 137e41f4b71Sopenharmony_ci }, 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci concat(hours, minutes) { 140e41f4b71Sopenharmony_ci return `${this.fill(hours)}:${this.fill(minutes)}`; 141e41f4b71Sopenharmony_ci }, 142e41f4b71Sopenharmony_ci} 143e41f4b71Sopenharmony_ci``` 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci 146