Gradients
The backgroundColor style property accepts CSS gradient strings in addition to solid colors. Gradients are rendered natively using SwiftUI gradient modifiers and are automatically clipped by borderRadius.
Invalid or unsupported gradient syntax is parsed in strict mode and results in no gradient background (instead of silent best-effort fallback).
Linear gradients
Supported directions: to right, to left, to top, to bottom, to top right, to top left, to bottom right, to bottom left.
Color stops
Explicit percentage positions are supported:
When positions are omitted, Voltra applies CSS-like stop fix-up:
- First and last unspecified stops default to
0%and100%. - Unspecified stops between explicit anchors are linearly interpolated.
- Non-monotonic explicit positions are clamped forward.
RGBA colors inside gradients
Radial gradients
Radial gradients are rendered with geometry-aware radii computed from the view size (closest-side, farthest-side, closest-corner, farthest-corner).
For ellipse, SwiftUI does not provide native elliptical radial gradients. Voltra approximates ellipse behavior by scaling a circular radial gradient.
Conic gradients
With border radius
Gradients are clipped by borderRadius automatically — no extra configuration needed:
Solid colors still work unchanged
Passing a plain color string to backgroundColor continues to work exactly as before:
Comparison with <LinearGradient> component
Use backgroundColor gradient strings for convenience and web-style syntax. Use <LinearGradient> when you need precise {x, y} coordinate control or dithering.
Scope and exclusions
- Supported core syntax:
linear-gradient(...),radial-gradient(...),conic-gradient(...). - Not supported in this parser:
repeating-linear-gradient(...),repeating-radial-gradient(...),repeating-conic-gradient(...).
