Logo
UI Elements

Comparison Slider

Reveal two images with a draggable divider

Overview

Comparison Slider reveals one image over another as the handle moves. It is useful for before-and-after views, graphics comparisons, and visual previews.

Preview

Usage

Create a Comparison Slider prefab.

Assign First Image and Second Image as Procedural Shapes and set their sprites.

Choose a horizontal or vertical split.


Customization

  • Enable Click To Move to jump to the pointer, or Drag On Hover to follow it without a press.
  • Reverse swaps the reveal direction. Auto Height can derive the layout from the image aspect ratio.

Public API

Use ComparisonSlider in the Evo.UI namespace.

Properties

NameTypeDescription
ValuefloatNormalized divider position from 0 to 1.
FirstSpriteSpriteSprite assigned to the first shape.
SecondSpriteSpriteSprite assigned to the second shape.
SliderOrientationOrientationHorizontal or vertical comparison.
ReverseboolReverses the reveal direction.
AutoHeightboolAutomatically sizes height from the image aspect.
PaddingfloatContent padding.

Methods

NameParametersDescription
SetReferences()ProceduralShape first, ProceduralShape second, RectTransform handle = null, RectTransform divider = nullAssigns image shapes and optional handle/divider references.
SetValueWithoutNotify()float inputChanges the split without invoking listeners.
Refresh()NoneRefreshes clipping and layout.

Events

NameTypeDescription
onValueChangedUnityEvent<float>Invoked with normalized position.

Example

ComparisonSliderExample.cs
using UnityEngine;
using Evo.UI;

public class ComparisonSliderExample : MonoBehaviour
{
    [SerializeField] private ComparisonSlider target;

    private void Start()
    {
        target.Value = 0.5f;
        target.SliderOrientation = ComparisonSlider.Orientation.Horizontal;
        target.onValueChanged.AddListener(value => Debug.Log($"Reveal: {value:P0}"));
    }
}

On this page