This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
按钮
用于显示原生按钮的 SwiftUI 按钮组件。
信息 如需跨平台使用,请参阅通用
Button— 它会根据平台渲染相应的原生组件。
Expo UI Button 与官方 SwiftUI Button API 相匹配,并支持通过 buttonStyle、controlSize 和其他修饰符设置样式。


安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基本按钮
带系统图像的按钮
仅图标按钮
使用 labelStyle 修饰符仅显示图标,同时保留标签以提供无障碍支持。
按钮样式
使用 buttonStyle 修饰符更改按钮的外观。可用样式包括:bordered、borderedProminent、borderless、plain、glass 和 glassProminent。
注意:
glass和glassProminent样式仅适用于使用 Xcode 26 构建的 iOS 26 及更高版本。
按钮边框形状
使用 buttonBorderShape 修饰符更改已设置样式的按钮形状。可用形状包括:automatic、capsule、roundedRectangle 和 circle(iOS 17 及更高版本)。
控件大小
使用 controlSize 修饰符调整按钮大小。可用大小包括:mini、small、regular、large 和 extraLarge。
注意:
extraLarge大小仅适用于 iOS 17 及更高版本。
按钮角色
使用 role 属性指定按钮的语义角色。可用角色包括:default、cancel 和 destructive。
着色按钮
使用 tint 修饰符更改按钮的颜色。
已禁用的按钮
使用 disabled 修饰符禁用按钮。
自定义标签内容
你可以将自定义组件作为 children 传入,以构建更复杂的按钮标签内容。
API
import { Button } from '@expo/ui/swift-ui';
Component
Type: React.Element<ButtonProps>
Displays a native button component.
Example
import { Button } from '@expo/ui/swift-ui'; import { buttonStyle, controlSize, tint, disabled } from '@expo/ui/swift-ui/modifiers'; <Button role="destructive" onPress={handlePress} label="Delete" modifiers={[ buttonStyle('bordered'), controlSize('large'), tint('#FF0000'), disabled(true) ]} />
unionCustom content for the button label. Use this for custom label views. Only nested elements are supported, not plain strings.
Acceptable values are: ReactElement<unknown, string | JSXElementConstructor<any>> | ReactElement[]
SFSymbols7_0A string describing the system image to display in the button.
Only used when label is provided.
stringTarget identifier for the button, used for identifying which button was pressed in widgets and live activities.
Types
Literal type: string
The role of the button.
default- The default button role.cancel- A button that cancels the current operation.destructive- A button that deletes data or performs a destructive action.close- A button that closes the view it is presented in. Given nolabeland no children, the system draws it as an xmark.
Acceptable values are: 'default' | 'cancel' | 'destructive' | 'close'