SwiftUI.js
Components

Text

Text is a view that displays one or more lines of read-only text. Use Text to display a string in your app's user interface. The Text view draws a string in a given font, with support for multiple lines, text truncation, and wrapping.

Text is a view that displays one or more lines of read-only text. Use Text to display a string in your app's user interface. The Text view draws a string in a given font, with support for multiple lines, text truncation, and wrapping.

Examples

Basic Usage

Preview unavailable for this example in the static docs build.

Show code
<Text>Hello, World!</Text>

Long Text

Preview unavailable for this example in the static docs build.

Show code
<Text>This is a longer text that demonstrates how the Text component handles multiple lines of content. It will wrap naturally based on the container width.</Text>

Line Limit

Preview unavailable for this example in the static docs build.

Show code
<Text lineLimit={2}>This is a very long text that will be truncated after the specified number of lines. The lineLimit prop controls how many lines are shown before truncation occurs.</Text>

Single Line Limit

Preview unavailable for this example in the static docs build.

Show code
<Text lineLimit={1}>This text will be truncated to a single line with an ellipsis if it exceeds the container width.</Text>

Custom Styling

Preview unavailable for this example in the static docs build.

Show code
<Text style={{
      fontSize: '24px',
      fontWeight: 'bold',
      color: '#007AFF'
    }}>Text with custom style</Text>

Multiple Texts in VStack

Preview unavailable for this example in the static docs build.

Show code
<VStack spacing={10}>
      <Text>First line</Text>
      <Text>Second line</Text>
      <Text>Third line</Text>
    </VStack>

Text in HStack

Preview unavailable for this example in the static docs build.

Show code
<HStack spacing={10}>
      <Text>Left</Text>
      <Text>Center</Text>
      <Text>Right</Text>
    </HStack>

API

PropTypeRequiredDescription
lineLimitnumberNoThe maximum number of lines to use for rendering text. If nil, no line limit applies. Default: undefined (no limit)

Inherits additional props from IBaseComponent.

Overview

Text is a view that displays one or more lines of read-only text. Use Text to display a string in your app's user interface. The Text view draws a string in a given font, with support for multiple lines, text truncation, and wrapping.

SwiftUI Correspondence: Similar to SwiftUI's Text.

Long Text

Text automatically wraps to multiple lines when needed:

Line Limit

Control the maximum number of lines displayed using the lineLimit prop:

Custom Styling

Apply custom styles to text:

Notes

  • Text automatically wraps when it exceeds the container width
  • Use lineLimit to control text truncation
  • Text supports all standard CSS text styling properties
  • Text can contain other React components as children

Best Practices

  1. Readability: Ensure sufficient contrast between text and background colors
  2. Line limits: Use lineLimit appropriately to prevent layout issues with long text
  3. Responsive: Text automatically adapts to container width
  4. Accessibility: Use semantic HTML and proper heading hierarchy
  5. Performance: Avoid excessive nested text components for better performance

On this page