This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
文本
一个用于显示样式化文本并支持嵌套文本的 SwiftUI Text 组件。
信息 如需跨平台使用,请参阅通用的
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 属性显示会随着时间推移自动更新的日期。这在 widgets 和 Live Activities 中尤其有用。
计时器间隔
使用 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.