This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 55).
图像
一个用于显示 SF Symbols 的 SwiftUI Image 组件。
For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.
Expo UI Image 使用 SwiftUI Image API 显示 SF Symbols。SF Symbols 是 Apple 提供的可配置符号库。
安装
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基本 SF Symbol
import { Host, Image } from '@expo/ui/swift-ui'; export default function BasicImageExample() { return ( <Host matchContents> <Image systemName="star.fill" /> </Host> ); }
带尺寸和颜色
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> ); }
带可变值
某些 SF Symbols 会根据可变值改变其外观。使用 variableValue 属性并传入 0.0 到 1.0 之间的值来控制渲染出的符号。需要 iOS 16.0+ 和 SF Symbols 4.0+。
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
Type: React.Element<ImageProps>
ColorValueThe color of the system image. Can be a color name like '#ff00ff', 'red', 'blue', etc.
SFSymbols7_0The name of the system image (SF Symbol). For example: 'photo', 'heart.fill', 'star.circle'
stringThe 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.
numberThe 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+).