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

背景

一个 SwiftUI 背景组件,用于在另一个视图后面叠加内容。

iOS
tvOS
Included in Expo Go
Recommended version:
~58.0.15

Expo UI 背景与官方 SwiftUI 的 background 修饰符相匹配,并在视图后绘制背景内容,按照指定的对齐方式定位。基础视图保持自己的大小。

安装

🌐 Installation

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.

用法

🌐 Usage

基本背景

🌐 Basic background

BackgroundExample.tsx
import { Background, Host, RoundedRectangle, Text, } from '@expo/ui/swift-ui'; import { font, foregroundStyle, padding, } from '@expo/ui/swift-ui/modifiers'; export default function BackgroundExample() { return ( <Host style={{ flex: 1, justifyContent: 'center', alignItems: 'center', }}> <Background> <Text modifiers={[ font({ size: 17, weight: 'semibold' }), padding({ all: 16 }), foregroundStyle('#1C1C1E'), ]}> Card title </Text> <Background.Content> <RoundedRectangle cornerRadius={12} modifiers={[foregroundStyle('#E8F0FE')]} /> </Background.Content> </Background> </Host> ); }

背景对齐

🌐 Background alignment

使用 alignment 属性可以将背景内容相对于基础视图进行定位。由于背景不会影响基础视图的布局,所以较小的背景可以固定在其某一边缘。

🌐 Use the alignment prop to position the background content relative to the base view. Because the background does not affect the layout of the base view, a smaller background can be pinned to one of its edges.

BackgroundAlignmentExample.tsx
import { Background, Host, Rectangle, Text, } from '@expo/ui/swift-ui'; import { font, foregroundStyle, frame, } from '@expo/ui/swift-ui/modifiers'; export default function BackgroundAlignmentExample() { return ( <Host style={{ flex: 1, justifyContent: 'center', alignItems: 'center', }}> <Background alignment="bottom"> <Text modifiers={[font({ size: 17 })]}> Underlined by its background </Text> <Background.Content> <Rectangle modifiers={[ frame({ height: 3 }), foregroundStyle('#007AFF'), ]} /> </Background.Content> </Background> </Host> ); }

应用接口

🌐 API

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

No API data file found, sorry!