RiveFit to determine scaling behavior and RiveAlignment to position content.
RiveFit
TheRiveFit enum controls how Rive content scales to fit within its container.
Fit Modes
Fit Mode Details
fill
fill
Stretches the content to fill the entire container. This may distort the aspect ratio of your animation.Use when: You want content to exactly fill the container, and aspect ratio isn’t critical.
contain (default)
contain (default)
Scales content to fit inside the container while maintaining aspect ratio. The entire animation will be visible.Use when: You want the entire animation visible without distortion.
cover
cover
Scales content to cover the entire container while maintaining aspect ratio. Content may be cropped.Use when: You want to fill the container without distortion, and cropping is acceptable.
fitWidth
fitWidth
Scales content to match the container’s width while maintaining aspect ratio.Use when: You want content to span the full width, allowing vertical scrolling if needed.
fitHeight
fitHeight
Scales content to match the container’s height while maintaining aspect ratio.Use when: You want content to span the full height, allowing horizontal scrolling if needed.
scaleDown
scaleDown
Like Use when: You want to prevent low-resolution content from appearing pixelated.
contain, but never scales content larger than its natural size.noFit
noFit
Content is rendered at its natural artboard size with no scaling.Use when: You want pixel-perfect rendering at the designed size.
layout
layout
Resizes the artboard itself to match the container dimensions.Use when: You want the Rive artboard to dynamically resize with the container.
RiveAlignment
TheRiveAlignment enum controls where content is positioned within its container.
Alignment Options
Alignment Grid
Using with RiveViewModel
Setting Fit and Alignment
SwiftUI Example
Layout Scale Factor
When usingRiveFit.layout, you can control the scale factor:
Dynamic Scale Factor Example
Using with RiveRenderer
For manual rendering, use theRiveRenderer alignment method:
Responsive Layout Example
Best Practices
Use contain for most cases
Use contain for most cases
The
.contain fit mode is the most common choice as it ensures the entire animation is visible without distortion.Use cover for background animations
Use cover for background animations
When using Rive content as a background,
.cover ensures the container is filled without distortion.Consider layout for adaptive designs
Consider layout for adaptive designs
The
.layout fit mode allows your artboard to resize dynamically, perfect for responsive interfaces.Test different screen sizes
Test different screen sizes
Always test your fit and alignment choices on different screen sizes and orientations to ensure content displays correctly.
Common Patterns
Full-Screen Background
Centered Icon
Hero Image
Related
- RiveViewModel - High-level view model with layout support
- Artboards - Understand artboard dimensions
- RiveView - Native view rendering