This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
切换
一个用于显示原生开关的 SwiftUI Toggle 组件。
关于跨平台使用,请参见通用的
Switch—— 它会根据平台渲染相应的原生组件。
Expo UI Toggle 与官方 SwiftUI Toggle API 保持一致,并支持通过 toggleStyle 修饰符进行样式设置。


安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基础切换
带系统图标的切换
切换样式
使用 toggleStyle 修饰符来更改切换控件的外观。可用样式有:automatic、switch 和 button。
注意:
button样式在 tvOS 上不可用。
着色切换
使用 tint 修饰符来更改切换控件的颜色。
自定义标签内容
你可以将自定义组件作为 children 传入,以创建更复杂的切换标签。使用多个 Text 视图,其中第一个表示标题,第二个表示副标题。
隐藏标签
使用 labelsHidden 修饰符隐藏标签,同时保留其可访问性。
API
import { Toggle } from '@expo/ui/swift-ui';
Component
Type: React.Element<ToggleProps>
A control that toggles between on and off states.
React.ReactNodeCustom content for the toggle label. Use multiple Text views where
the first represents the title and the second represents the subtitle.
(isOn: boolean) => voidA callback that is called when the toggle's state changes.
isOn: booleanThe new state of the toggle.
SFSymbolThe name of the SF Symbol to display alongside the label.