import{Host,Text}from'@expo/ui/swift-ui';import{ font, foregroundStyle }from'@expo/ui/swift-ui/modifiers';exportdefaultfunctionStyledTextExample(){return(<HostmatchContents><Textmodifiers={[font({ size:24, weight:'bold'}),foregroundStyle('blue')]}>
Large Bold Blue Text
</Text></Host>);}
Nested text (per-segment styling)
Nest Text components to style individual segments differently. This is useful for inline formatting, such as bold or colored words within a sentence.
Note: Nested text uses SwiftUI's Text concatenation, so only modifiers that return Text (such as bold, italic, font, foregroundColor, and foregroundStyle with color) will apply to nested segments.
Combine multiple styled segments for rich text formatting.
MixedStylesExample.tsx
import{Host,Text}from'@expo/ui/swift-ui';import{ bold, italic, foregroundStyle, font }from'@expo/ui/swift-ui/modifiers';exportdefaultfunctionMixedStylesExample(){return(<HostmatchContents><Text>
This is <Textmodifiers={[bold()]}>bold</Text>, <Textmodifiers={[italic()]}>italic</Text>,
and <Textmodifiers={[foregroundStyle('orange')]}>colored</Text> text.
</Text></Host>);}
Font weights
Use the font modifier to apply different font weights.
Use the font modifier with a family parameter to use custom fonts. You can load custom fonts using expo-font library.
CustomFontExample.tsx
import{Host,Text,VStack}from'@expo/ui/swift-ui';import{ font }from'@expo/ui/swift-ui/modifiers';exportdefaultfunctionCustomFontExample(){return(<HostmatchContents><VStackspacing={4}><Textmodifiers={[font({ family:'Inter-Bold', size:18})]}>Inter Bold</Text><Textmodifiers={[font({ family:'Inter-Regular', size:18})]}>Inter Regular</Text></VStack></Host>);}
Text with line limit
Use the lineLimit modifier to truncate text after a certain number of lines.
LineLimitExample.tsx
import{Host,Text}from'@expo/ui/swift-ui';import{ lineLimit }from'@expo/ui/swift-ui/modifiers';exportdefaultfunctionLineLimitExample(){const longText ='This is a very long text that will be truncated after two lines. '.repeat(5);return(<HostmatchContents><Textmodifiers={[lineLimit(2)]}>{longText}</Text></Host>);}
Markdown
Use the markdownEnabled property to enable Markdown formatting for the text content.
MarkdownTextExample.tsx
import{Host,Text,VStack}from'@expo/ui/swift-ui';exportdefaultfunctionMarkdownTextExample(){return(<HostmatchContents><VStackspacing={4}><TextmarkdownEnabled>Regular text.</Text><TextmarkdownEnabled>
This is **bold text**, *italic text* and ***text in both bold and italic***.
</Text><TextmarkdownEnabled>~~Strikethrough text~~</Text><TextmarkdownEnabled>`This is monospaced text`</Text><TextmarkdownEnabled>
Visit the [Expo Docs](https://docs.expo.dev/versions/latest/sdk/ui/) to learn more about
Expo UI
</Text></VStack></Host>);}