Skip to main content

Overview

RiveTextValueRun represents a text run within a Rive animation, allowing you to read and update text content dynamically at runtime.

Definition

@interface RiveTextValueRun : NSObject
- (NSString*)text;
- (void)setText:(NSString*)newValue;
@end

Methods

text

- (NSString*)text
Returns the current text value of the text run. Returns: The current text as a string.

setText

- (void)setText:(NSString*)newValue
Sets a new text value for the text run. Parameters:
  • newValue: The new text string to display.

Usage

// Get text runs from an artboard
let artboard = riveFile?.artboard()
let textRuns = artboard?.textValueRuns() ?? []

// Read current text value
if let firstRun = textRuns.first {
    let currentText = firstRun.text()
    print("Current text: \(currentText)")
}

// Update text value
for run in textRuns {
    run.setText("Updated text")
}

Dynamic Text Updates

// Update text based on user input
class AnimationViewController: UIViewController {
    var viewModel: RiveViewModel?
    var textRuns: [RiveTextValueRun] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        viewModel = RiveViewModel(fileName: "text_animation")
        viewModel?.setView(riveView) { [weak self] view in
            if let artboard = view.riveModel?.getArtboard() {
                self?.textRuns = artboard.textValueRuns()
            }
        }
    }
    
    func updateAnimationText(_ newText: String) {
        for run in textRuns {
            run.setText(newText)
        }
    }
}

Multiple Text Runs

// Update specific text runs by index
let textRuns = artboard?.textValueRuns() ?? []

if textRuns.count > 0 {
    textRuns[0].setText("Title Text")
}

if textRuns.count > 1 {
    textRuns[1].setText("Subtitle Text")
}

Localization Example

// Update text runs with localized strings
func localizeAnimation() {
    guard let artboard = riveFile?.artboard() else { return }
    let textRuns = artboard.textValueRuns()
    
    for (index, run) in textRuns.enumerated() {
        let localizedKey = "animation.text.\(index)"
        let localizedText = NSLocalizedString(localizedKey, comment: "")
        run.setText(localizedText)
    }
}
  • RiveArtboard - Provides access to text runs via textValueRuns()
  • RiveFile - Contains artboards with text runs
  • RiveViewModel - Use to access and modify text at runtime

Build docs developers (and LLMs) love