Skip to main content
196

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Apple docs
Data displayApple

Image comparison

Compare two images with a controlled reveal and native adjustable slider.

Public APILumenImageComparisonApple / SwiftUISwift product: LumenUI

Apple availability

Supported native targets

Import LumenUI in the target that uses this component. iPad support follows the iOS package baseline and uses native iPad layout behavior.

iPhone · iOS 16+iPad · iPadOS 16+Mac · macOS 13+Apple Vision · visionOS 1+

Native example

Use Image comparison

The value is the visible after fraction, clamped to zero through one; nonfinite input falls back to one half. The application owns image loading, errors, cache, fit and descriptions; provide React Native sources, SwiftUI content builders or Compose painters.

Image comparison rendered in the iPhone simulator Lumen playground
Captured exampleiPhone simulator
swift
import LumenUI
import SwiftUI

struct CompareEdits: View {
    @State private var position = 0.5
    var body: some View {
        LumenImageComparison("Compare edits", value: $position,
            beforeLabel: "Before", afterLabel: "After") {
            Image("before").resizable().scaledToFill()
        } after: {
            Image("after").resizable().scaledToFill()
        }
    }
}

Reference

Public API

The primary shared and platform-specific options exposed by LumenImageComparison.

APIValues or typeDefaultDescription
_ labelStringRequiredNames the adjustable reveal.
valueBinding<Double>RequiredControls the visible after fraction, zero through one.
before / after@ViewBuilder closuresRequiredProvides application-owned SwiftUI image content and image fit modifiers.
beforeLabel / afterLabelStringBefore / AfterLocalizes image labels and adjustment state.
aspectRatioCGFloat16 / 9Accepts 0.1 through 10; otherwise uses 16:9.
.environment(\.locale, ...)LocaleEnvironmentFormats the percentage.
.disabled(...)BoolfalseDisables the native slider while preserving images.

Native behavior

Design and accessibility

When to use it

The value is the visible after fraction, clamped to zero through one; nonfinite input falls back to one half. The application owns image loading, errors, cache, fit and descriptions; provide React Native sources, SwiftUI content builders or Compose painters.

Accessibility

Exposes a named native slider with localized percentage state for touch, keyboard, and screen-reader adjustment.

Shared component

Available on other platforms

React NativeAndroid / Compose
Apple docsSwiftUI package