This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Toggle
用于显示原生切换开关的 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.
用法
基本 Toggle
带系统图像的 Toggle
Toggle 样式
使用 toggleStyle 修饰符更改 Toggle 的外观。可用样式包括:automatic、switch 和 button。
注意: tvOS 不支持
button样式。
着色 Toggle
使用 tint 修饰符更改 Toggle 的颜色。
自定义标签内容
你可以将自定义组件作为 children 传入,以创建更复杂的 Toggle 标签。使用多个 Text 视图,其中第一个表示标题,第二个表示副标题。
隐藏标签
使用 labelsHidden 修饰符隐藏标签,同时保留其无障碍功能。
API
import { Toggle } from '@expo/ui/swift-ui';
Component
Type: React.Element<ToggleProps>
A control that toggles between on and off states.
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.
SFSymbols7_0The name of the SF Symbol to display alongside the label.