Skip to main content

Switch

渲染布尔输入。

¥Renders a boolean input.

这是一个受控组件,需要 onValueChange 回调来更新 value 属性,以便组件反映用户操作。如果 value 属性未更新,组件将继续渲染提供的 value 属性,而不是任何用户操作的预期结果。

¥This is a controlled component that requires an onValueChange callback that updates the value prop in order for the component to reflect user actions. If the value prop is not updated, the component will continue to render the supplied value prop instead of the expected result of any user actions.

示例

¥Example


参考

¥Reference

属性

¥Props

视图属性

¥View Props

继承 视图属性

¥Inherits View Props.


disabled

如果为 true,用户将无法切换开关。

¥If true the user won't be able to toggle the switch.

类型默认
boolfalse

ios_backgroundColor
iOS

在 iOS 上,自定义背景颜色。当开关值为 false 或开关被禁用(且开关为半透明)时,可以看到该背景颜色。

¥On iOS, custom color for the background. This background color can be seen either when the switch value is false or when the switch is disabled (and the switch is translucent).

类型
color

onChange

当用户尝试更改开关的值时调用。接收更改事件作为参数。如果你只想接收新值,请改用 onValueChange

¥Invoked when the user tries to change the value of the switch. Receives the change event as an argument. If you want to only receive the new value, use onValueChange instead.

类型
function

onValueChange

当用户尝试更改开关的值时调用。接收新值作为参数。如果你想接收事件,请使用 onChange

¥Invoked when the user tries to change the value of the switch. Receives the new value as an argument. If you want to instead receive an event, use onChange.

类型
function

thumbColor

前景开关句柄的颜色。如果在 iOS 上设置此选项,开关句柄将失去投影。

¥Color of the foreground switch grip. If this is set on iOS, the switch grip will lose its drop shadow.

类型
color

trackColor

开关轨道的自定义颜色。

¥Custom colors for the switch track.

iOS:当开关值为 false 时,轨道收缩到边界内。如果要更改缩小轨道所暴露的背景颜色,请使用 ios_backgroundColor

¥iOS: When the switch value is false, the track shrinks into the border. If you want to change the color of the background exposed by the shrunken track, use ios_backgroundColor.

类型
object: {false: color, true: color}

value

开关的值。如果为真,开关将打开。默认值为 false。

¥The value of the switch. If true the switch will be turned on. Default value is false.

类型
bool