Skip to content

CompactSlider is a SwiftUI control for macOS, iOS, watchOS and visionOS.

License

Notifications You must be signed in to change notification settings

buh/CompactSlider

Repository files navigation

CompactSlider

CompactSlider is a highly customizable multi-purpose slider control for SwiftUI. It can be used to select a single value, or a range of values, or multiple values, or a point in a grid, or a polar point in a circular grid. The slider can be displayed horizontally, vertically, or in a (circular) grid. The slider can be customized with a variety of styles and options, including the possibility to design your own style.

The slider is a replacement for the build-in slider and is designed specifically for SwiftUI. For me, the main motivation for writing a component that already exists is the very slow performance under macOS 12 and below (e.g. when you need to resize the screen with multiple sliders or when animating) and the severely outdated design at that time.

I was inspired by the slider design that Apple's Photos app developed, which makes heavy use of sliders. Also new sliders in the Camera app on iPhone 16 Pro.

Slider Types

The slider basically defines two variants: a linear slider and a grid slider. The linear slider can be horizontal or vertical, and also scrollable, where the handle is still and the scale is moving.

The grid slider can be used to select a point in a grid or a polar point in a circular grid. The point in the grid represents a value of the x and y axis. The polar point represents a value of the angle and radius.

Possible slider types defined by the CompactSliderType:

  • a horizontal slider with alignments: leading, center, trailing.
  • a vertical slider with alignments: top, center, bottom.
  • a scrollable horizontal slider.
  • a scrollable vertical slider.
  • a grid slider.
  • a circular grid slider.

Requirements

  • Swift 5.9+
  • Xcode 15+
  • SwiftUI 3+
  • macOS 12+
  • iOS 15+
  • watchOS 8+
  • visionOS 1+

Installation

  1. In Xcode go to FileAdd Packages....
  2. Search for the link below and click Add Package:
https://github.com/buh/CompactSlider.git
  1. Select to which target you want to add it and select Add Package.

Documentation

Getting started

The default style composition

image

Demo

The demo package contains several use cases.

Demo

macOS iOS
macOS iOS
macOS iOS
macOS iOS

GridDemo

macOS iOS
macOS iOS

CircularGridDemo

macOS iOS
macOS iOS

SystemDemo

macOS iOS
macOS iOS

visionOS visionOS

WatchOSDemo

Horizontal Vertical Grid Circular Grid
WatchOSDemo WatchOSDemo WatchOSDemo WatchOSDemo

Version 1.0 (deprecated)

Version 1.0 is deprecated and no longer supported. You can find the documentation for version 1.0 in the file: README v1.

Support

You can buy me a coffee here ☕️

License

CompactSlider is available under the MIT license