图片

用于显示 SF 符号的 SwiftUI 图片组件。

iOS
tvOS
Bundled version:
~55.0.2

Expo UI 图片使用 SwiftUI Image API 显示 SF 符号。SF 符号是苹果提供的一个可配置符号库。

🌐 Expo UI Image displays SF Symbols using the SwiftUI Image API. SF Symbols are a library of configurable symbols provided by Apple.

安装

🌐 Installation

Terminal
npx expo install @expo/ui

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

用法

🌐 Usage

基本 SF 符号

🌐 Basic SF Symbol

BasicImageExample.tsx
import { Host, Image } from '@expo/ui/swift-ui'; export default function BasicImageExample() { return ( <Host matchContents> <Image systemName="star.fill" /> </Host> ); }

按尺寸和颜色

🌐 With size and color

ImageSizeColorExample.tsx
import { Host, HStack, Image } from '@expo/ui/swift-ui'; export default function ImageSizeColorExample() { return ( <Host matchContents> <HStack spacing={16}> <Image systemName="heart.fill" size={24} color="red" /> <Image systemName="star.fill" size={32} color="orange" /> <Image systemName="bell.fill" size={40} color="blue" /> </HStack> </Host> ); }

带有变量值

🌐 With variable value

某些 SF 符号会根据变量值改变其外观。使用 variableValue 属性,取值范围在 0.0 到 1.0 之间,以控制渲染的符号。需要 iOS 16.0 及以上版本和 SF Symbols 4.0 及以上版本。

🌐 Some SF Symbols alter their appearance based on a variable value. Use the variableValue prop with a value between 0.0 and 1.0 to control the rendered symbol. Requires iOS 16.0+ and SF Symbols 4.0+.

ImageVariableExample.tsx
import { Host, HStack, Image } from '@expo/ui/swift-ui'; export default function ImageVariableExample() { return ( <Host matchContents> <HStack spacing={16}> <Image systemName="chart.bar.fill" size={32} variableValue={0.3} /> <Image systemName="chart.bar.fill" size={32} variableValue={0.6} /> <Image systemName="chart.bar.fill" size={32} variableValue={1.0} /> </HStack> </Host> ); }

应用接口

🌐 API

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

Component

Image

iOS
tvOS

Type: React.Element<ImageProps>

ImageProps

color

iOS
tvOS
Optional • Type: ColorValue

The color of the system image. Can be a color name like '#ff00ff', 'red', 'blue', etc.

onPress

iOS
tvOS
Optional • Type: () => void

Callback triggered when the view is pressed.

size

iOS
tvOS
Optional • Type: number

The size of the system image.

systemName

iOS
tvOS
Optional • Type: SFSymbols7_0

The name of the system image (SF Symbol). For example: 'photo', 'heart.fill', 'star.circle'

uiImage

iOS
tvOS
Optional • Type: string

The URI of the local image file to display. For example: 'file:///path/to/image.jpg' Performs a synchronous read operation that blocks the main thread.

variableValue

iOS16.0+
tvOS16.0+
Optional • Type: number

The variable value that alters the symbol's appearance. A number between 0.0 and 1.0. Only works with SF Symbols that support variable values (SF Symbols 4.0+).