Reference version

This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Label

一个用于显示带图标文本的 SwiftUI Label 组件。

iOS
tvOS
Included in Expo Go
Recommended version:
~58.0.1

Expo UI Label 与官方 SwiftUI Label API 相匹配,可在图标旁显示标题。

包含 SF Symbols 的三个 Label 行,位于 Form 中包含 SF Symbols 的三个 Label 行,位于 Form 中

安装

Terminal
- npx expo install @expo/ui
- yarn expo install @expo/ui
- pnpm expo install @expo/ui
- bun expo install @expo/ui

If you are installing this in an existing React Native app, make sure to install expo in your project.

用法

带有 SF Symbol 的基本 Label

BasicLabelExample.tsx
import { Host, Label } from '@expo/ui/swift-ui'; export default function BasicLabelExample() { return ( <Host style={{ flex: 1 }}> <Label title="Favorites" systemImage="star.fill" /> </Host> ); }

使用自定义图标

使用 icon 属性提供自定义 React 节点作为图标,而不是 SF Symbol。

LabelCustomIconExample.tsx
import { Host, Label, Image } from '@expo/ui/swift-ui'; export default function LabelCustomIconExample() { return ( <Host matchContents> <Label title="Custom Icon" icon={ <Image systemName="sparkles" size={20} color="purple" /> } /> </Host> ); }

仅显示图标

使用 labelStyle 修饰符和 iconOnly 仅显示图标。出于无障碍考虑,请始终提供 title,即使它不会显示。

LabelIconOnlyExample.tsx
import { Host, Label } from '@expo/ui/swift-ui'; import { labelStyle } from '@expo/ui/swift-ui/modifiers'; export default function LabelIconOnlyExample() { return ( <Host style={{ flex: 1 }}> <Label title="Settings" systemImage="gear" modifiers={[labelStyle('iconOnly')]} /> </Host> ); }

API

import { Label } from '@expo/ui/swift-ui';

Component

Label

iOS
tvOS

Type: React.Element<LabelProps>

Renders a native label view, which could be used in a list or section.

LabelProps

children

iOS
tvOS
Optional • Type: ReactNode

Custom title view. Accepts any React node (for example, a VStack with title and subtitle). When provided, this takes precedence over title.

color

iOS
tvOS
Optional • Type: ColorValue

The color of the label icon.

icon

iOS
tvOS
Optional • Type: ReactNode

Custom icon view to be displayed in the label. When provided, this takes precedence over systemImage.

systemImage

iOS
tvOS
Optional • Type: SFSymbols7_0

The name of the SFSymbol to be displayed in the label.

title

iOS
tvOS
Optional • Type: string

The title text to be displayed in the label.