Overview
Text Runs in Rive are named text elements that can be updated programmatically. The iOS Runtime provides methods to get and set text values on Text Runs within your artboards.Basic Usage
Setting Text Values
Use thesetTextRunValue method to update text content:
Getting Text Values
Retrieve the current text value from a Text Run:Working with Nested Text Runs
For Text Runs nested within artboards or groups, use the path parameter:/) to separate nested levels.
SwiftUI Example
Here’s a complete SwiftUI example with a text input field:UIKit Example
Using RiveTextValueRun Directly
For more direct control, you can accessRiveTextValueRun objects through the artboard:
Updating When Not Playing
When the animation is not playing, you need to manually advance the view to see text changes:setTextRunValue methods in RiveViewModel automatically handle this for you.
Formatting and Styling
Text styling (font, size, color, alignment, etc.) is controlled in the Rive editor. The runtime only updates the text content itself, not the styling. To change styles dynamically, consider:- Using different Text Runs with pre-configured styles
- Using Data Binding with view model properties
- Switching between different artboards or animations
Error Handling
ThesetTextRunValue methods throw errors if the text run cannot be found:
- The name of the text run that couldn’t be found
- That the active artboard doesn’t contain the specified text run
Best Practices
- Name Your Text Runs: Give meaningful names to Text Runs in the Rive editor for easy reference
- Handle Errors: Always wrap
setTextRunValuecalls in do-catch blocks - Use Optional Binding: When getting text values, use optional binding to handle nil cases
- Manual Refresh: Remember to advance the view when updating text while not playing
- Path Syntax: Use forward slashes for nested paths, matching the hierarchy in your Rive file
Text Run Requirements
Note: Text features require theWITH_RIVE_TEXT compilation flag, which is enabled by default in the iOS Runtime.
Common Use Cases
User Profiles
Scores and Counters
Dynamic Labels
See Also
- Custom Fonts - Using custom and fallback fonts
- Data Binding - Alternative approach for dynamic content