This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 57).
文本
一个用于显示样式化文本并支持嵌套文本的 SwiftUI 文本组件。
信息 有关跨平台使用,请查看通用的
Text—— 它会针对每个平台渲染对应的原生组件。
Expo UI Text 与官方 SwiftUI Text API 保持一致。


安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基本文本
带修饰符的文本
使用修饰符来样式化整段文本。
嵌套文本(按片段设置样式)
嵌套 Text 组件以对单个片段应用不同样式。这对于行内格式化非常有用,例如句子中的加粗或彩色词语。
注意: 嵌套文本使用 SwiftUI 的 Text 拼接,因此只有返回
Text的修饰符(例如bold、italic、font、foregroundColor以及带颜色的foregroundStyle)才会应用于嵌套片段。
混合行内样式
组合多个带样式的片段以实现富文本格式化。
字体字重
使用 font 修饰符来应用不同的字体字重。
字体设计
使用 font 修饰符来应用不同的字体设计。
自定义字体
使用带有 family 参数的 font 修饰符来使用自定义字体。你可以使用 expo-font 库加载自定义字体。
带行数限制的文本
使用 lineLimit 修饰符在一定行数后截断文本。
Markdown
使用 markdownEnabled 属性为文本内容启用 Markdown 格式。
自动更新的日期
使用 date 和 dateStyle 属性来显示会随着时间流逝自动更新的日期。这在小组件和实时活动中尤其有用。
计时器区间
使用 timerInterval 来显示实时倒计时或正计时器。这需要 iOS/tvOS 16+。
注意:
timerInterval、countsDown和pauseTime需要 iOS 16.0+ / tvOS 16.0+。在较旧版本中,计时器区间将不会渲染。
API
import { Text } from '@expo/ui/swift-ui';
Component
Type: React.Element<TextProps>
boolean • Default: trueWhether the timer counts down (true) or up (false).
DateA date to display using the specified dateStyle. The text auto-updates as time passes.
TextDateStyle • Default: 'date'The style used to format the date prop.
booleanEnables Markdown formatting for the text content using SwiftUI LocalizedStringKey.
ClosedRangeDateA time interval to display as a live-updating timer.