SwiftUI Sliders with custom styles

Overview

Custom SwiftUI sliders and tracks.

This package allows you to build highly customizable sliders and tracks for iOS, macOS and Mac Catalyst.

Features

  • Build your own sliders and tracks using composition
  • Highly customizable
  • Horizontal and Vertical styles
  • Range and XY values
  • Different sizes for lower and upper range thumbs

Styles

  • HorizontalValueSliderStyle
  • VerticalValueSliderStyle
  • HorizontalRangeSliderStyle
  • VerticalRangeSliderStyle
  • RectangularPointSliderStyle

How to use

Add this swift package to your project

[email protected]:spacenation/swiftui-sliders.git

Import and use

import Sliders
import SwiftUI

struct ContentView: View {
    @State var value = 0.5
    @State var range = 0.2...0.8
    @State var x = 0.5
    @State var y = 0.5
    
    var body: some View {
        Group {
            ValueSlider(value: $value)
            RangeSlider(range: $range)
            PointSlider(x: $x, y: $y)
        }
    }
}

For more examples open /Examples/SlidersExamples.xcodeproj

Customization with style

Use any SwiftUI view modifiers to create custom tracks and thumbs.

RangeSlider(range: $model.range2)
    .rangeSliderStyle(
        HorizontalRangeSliderStyle(
            track:
                HorizontalRangeTrack(
                    view: Capsule().foregroundColor(.purple)
                )
                .background(Capsule().foregroundColor(Color.purple.opacity(0.25)))
                .frame(height: 8),
            lowerThumb: Circle().foregroundColor(.purple),
            upperThumb: Circle().foregroundColor(.purple),
            lowerThumbSize: CGSize(width: 32, height: 32),
            upperThumbSize: CGSize(width: 32, height: 32),
            options: .forceAdjacentValue
        )
    )

SDKs

  • iOS 13+
  • Mac Catalyst 13.0+
  • macOS 10.15+
  • Xcode 11.0+

Roadmap

  • Circular sliders and tracks

Code Contributions

Feel free to contribute via fork/pull request to master branch. If you want to request a feature or report a bug please start a new issue.

Coffee Contributions

If you find this project useful please consider becoming my GitHub sponsor.

Comments
  • Adding onEditingChange breaks Swift

    Adding onEditingChange breaks Swift

    I can't get this to compile: If I take out onEditingChange it will compile.

        RangeSlider(range: $range)
                .rangeSliderStyle(
                    HorizontalRangeSliderStyle(
                        track:
                        HorizontalRangeTrack(
                            view: Capsule().foregroundColor(Color("TPOrange"))
                        )
                            .background(Capsule().foregroundColor(Color("TPOrange").opacity(0.30)))
                            .frame(height: 8),
                        lowerThumb: Circle().foregroundColor(Color(UIColor(named: "TPLightGrey")!)),
                        upperThumb: Circle().foregroundColor(Color(UIColor(named: "TPLightGrey")!)),
                        lowerThumbSize: CGSize(width: 32, height: 32),
                        upperThumbSize: CGSize(width: 32, height: 32),
                        options: .forceAdjacentValue,
                        onEditingChanged: {
                           value in
                           if !value {
                               self.queryCallback()
                           }
                       }
                    )
                   
            ).padding([.horizontal]).frame(height: 64)
    
    opened by jimijon 7
  • The thumbs don't show for me.

    The thumbs don't show for me.

    Used a simple example:

    RangeSlider(range: $range)
                                       .rangeSliderStyle(
                                           HorizontalRangeSliderStyle(
                                               track:
                                                   HorizontalRangeTrack(
                                                       view: Capsule().foregroundColor(.purple)
                                                   )
                                                   .background(Capsule().foregroundColor(Color.purple.opacity(0.25)))
                                                   .frame(height: 8),
                                               lowerThumb: Circle().foregroundColor(.purple),
                                               upperThumb: Circle().foregroundColor(.purple),
                                               lowerThumbSize: CGSize(width: 32, height: 32),
                                               upperThumbSize: CGSize(width: 32, height: 32),
                                               options: .forceAdjacentValue
                                           )
                                       )
    

    But the thumbs don't show. Any ideas?

    opened by jimijon 4
  • Track colors

    Track colors

    First of all, thanks for the awesome library. Would love to see more examples of usage. I'm trying to set different track colors for active (left of thumb) and inactive (right of the thumb) parts. How can I do that? Any help is appreciated.

    enhancement iOS macOS 
    opened by gemiren 2
  • Click on slider track should adjust value

    Click on slider track should adjust value

    With NSSlider on macOS, you can click on the slider track to move the thumb to the clicked position. When running on macOS, these sliders should do the same.

    opened by thompsonate 2
  • LowerThumb moves UpperThumb

    LowerThumb moves UpperThumb

    Hi, I'm using this library to create a RangeSlider but I have a problem. When I move the lower thumb and it reaches the position of upper thumb instead of stop the movement, the lower thumb pushes the upper thumb (see the attached video). I think this behavior is not natural on app development. Is there a way to fix it?

    https://user-images.githubusercontent.com/13442110/143972064-c740edbd-b02e-45e9-a150-20633b3f7b85.mov

    opened by DanyGZ 1
  • Thumb over the range slider

    Thumb over the range slider

    Range 0.0 ... 1.0 Very simple. As the title with a value beyond the range the thumb goes beyond. Here a comparison with system sliders that stops at the end. Problem found only with MacOS Monterey Beta 6 (21A5506J).

    In addition the Resources andExamples folders in Package are missing.

    range

    slider-range-bug.swift.zip

    bug iOS macOS 
    opened by gmcusaro 1
  • Range slider in documentation example only displays one handle

    Range slider in documentation example only displays one handle

    RangeSlider(range: $model.range2)
        .rangeSliderStyle(
            HorizontalRangeSliderStyle(
                track:
                    HorizontalRangeTrack(
                        view: Capsule().foregroundColor(.purple)
                    )
                    .background(Capsule().foregroundColor(Color.purple.opacity(0.25)))
                    .frame(height: 8),
                lowerThumb: Circle().foregroundColor(.purple),
                upperThumb: Circle().foregroundColor(.purple),
                lowerThumbSize: CGSize(width: 32, height: 32),
                upperThumbSize: CGSize(width: 32, height: 32),
                options: .forceAdjacentValue
            )
        )
    

    This is what's rendered:

    Screen Shot 2021-04-18 at 7 34 36 AM
    opened by AdrianBinDC 1
  • Request (possibly just for advice): A star slider with half-star values

    Request (possibly just for advice): A star slider with half-star values

    There are tutorials available for how to make a star rating UI component, but I'm really hoping to do something a little more complicated, and I think it's going to require handling the rating as a slider (with an invisible knob).

    My idea is that the "bar" will be a row of five stars and then sliding along it results in this:

    0.0 = "star" x 5 0.5 = ("star.leadinghalf.fill" x 1) + ("star" x 4) 1.0 = ("star.fill" x 1) + ("star" x 4) 1.5 = ("star.fill" x 1) + ("star.leadinghalf.fill" x 1) + ("star" x 3) .. and so forth up to ("star.fill" x 5)

    I've tried altering your sliders to do something like this, and clearly I did it wrong because any attempt to "slide" along the row resulted in the row of stars changing position on the screen.

    Is this something that should be handled as a slider, or should I instead perhaps handle it so that each star is a button that starts at "star (empty)" and changes to "star.leadinghalf.fill" the first time it's tapped, and then to "star.fill" if it's tapped again, before cycling back to being empty?

    opened by NCrusher74 1
  • Dragging the slider isn't smooth when thumb is small (but interactivethumb size is large)

    Dragging the slider isn't smooth when thumb is small (but interactivethumb size is large)

    I have a minimal slider with a small thumb size (8x8) but a 36x36 interactive thumbsize. I have the options set to [.interactiveTrack]

    I notice that a tap on the track works great, but a drag updates the track value after a second on so, without any smoothness.

    opened by quantamrhino 1
  • How to specify a minimum selectable range for HRangeSlider?

    How to specify a minimum selectable range for HRangeSlider?

    Hi. First of all, thank you for an awesome library!

    A quick question: How do I specify a minimum selectable range for an HRangeSlider? Couldn't find it in the options.

    opened by skryshi 1
  • Alternative step value with option key

    Alternative step value with option key

    Hi, thanks for creating such a customizable control! Sometimes it is helpful to have more precise step adjustments, such as 0.1 if 0.5 was the step value. Would it be possible to have an option to have an alternative step value on pressing the option modifier key?

    opened by godly-devotion 0
  • Are There Any Examples Besides the Two in the README?

    Are There Any Examples Besides the Two in the README?

    Love the project! Wondering (as my title suggests) if there are any other examples usages of this library or documentation somewhere? I've successfully hacked my way to getting a value slider working the way I wanted, but I'm having a hard time figuring out the range slider.

    Thank you for this project!

    opened by alexwhb 2
  • Minimum Difference between upperBound  and lowerBound

    Minimum Difference between upperBound and lowerBound

    I am using this library for range slider in my project for age range. now i want minimum 5 years of difference in between minimum age and maximum selected i am unable to find any thing regarding this.

    enhancement iOS macOS 
    opened by Noor-Ahmed-Natali 3
  • Erros on xCode 13.0.

    Erros on xCode 13.0.

    Hello,

    I added the package to my project. When on xCode 13.0, I get errors saying "Ambiguous use of 'accentColor'". Maybe Color.accentColor should be used instead of just .accentColor in the source code when using .accentColor as a parameter call. Could you please resolve this?

    Kind Regards, Stefan

    enhancement 
    opened by Stefan-Hopman 2
Releases(2.1.0)
Owner
SpaceNation
Software development team
SpaceNation
VolumeControl is a custom volume control for iPhone featuring a well-designed round slider.

#VolumeControl VolumeControl is a custom volume control for iPhone featuring a well-designed round slider. Preview Usage // Include VolumeControl.h in

12Rockets 81 Oct 11, 2022
A custom reusable slider control with 2 thumbs (range slider).

MARKRangeSlider A custom reusable slider control with 2 thumbs (range slider). Values range is between minimumValue and maximumValue (from 0 to 1 by d

Vadym Markov 181 Nov 21, 2022
StepSlider its custom implementation of slider such as UISlider for preset integer values.

StepSlider StepSlider its custom implementation of slider such as UISlider for preset values. Behind the scenes StepSlider manipulate integer indexes.

spromicky 520 Dec 20, 2022
A custom reusable circular / progress slider control for iOS application.

HGCircularSlider Example To run the example project, clone the repo, and run pod install from the Example directory first. You also may like HGPlaceho

Hamza Ghazouani 2.4k Jan 4, 2023
A reusable Slider View made with SwiftUI

ZSlider A reusable Slider View made with SwiftUI. Installation: Minimum version iOS 13 In Xcode go to File -> Swift Packages -> Add Package Dependency

null 7 Dec 15, 2022
TriggerSlider is a simple SwiftUI trigger slider

TriggerSlider is a simple SwiftUI trigger slider which can be used instead of a button, e.g. in a situation where the

Dominik Butz 4 Dec 16, 2022
SwiftUI Clock Time Picker

SwiftUI Clock Time Picker example An exampe of using ClockTimePicker library. Clock with hands ClockTimePicker is a SwiftUI view that displays a clock

workingDog 7 Dec 26, 2022
Dragger - A Customizable Drag Slider swiftUI view

Dragger A customizable SwiftUI Dragger view. Installation In Xcode add https://g

Kiefer Wiessler 4 Dec 19, 2022
CompactSlider is a SwiftUI control for macOS, iOS and watchOS.

CompactSlider is a control for selecting a value from a bounded linear range of values. The slider is a replacement for the build-in slider and is des

Alexey Bukhtin 244 Dec 13, 2022
null 13 Oct 28, 2022
A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles while pushing or popping a view controller for all orientations. And you don't need to write any line of code for it, it all happens automatically.

Zhouqi Mo 3.3k Dec 21, 2022
A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles while pushing or popping a view controller for all orientations. And you don't need to write any line of code for it, it all happens automatically.

Zhouqi Mo 3.3k Dec 21, 2022
FSPagerView is an elegant Screen Slide Library. It is extremely helpful for making Banner View、Product Show、Welcome/Guide Pages、Screen/ViewController Sliders.

SWIFT OBJECTIVE-C FSPagerView is an elegant Screen Slide Library implemented primarily with UICollectionView. It is extremely helpful for making Banne

Wenchao Ding 6.7k Jan 2, 2023
HomeWork3.2 - How to work with sliders, textfield, keyboard, view

HomeWork3.2 How to work with sliders, textfield, keyboard, view

Artur 1 Jan 26, 2022
SwiftUI Charts with custom styles

SwiftUI Charts Build custom charts with SwiftUI Styles Line Chart(data: [0.1, 0.3, 0.2, 0.5, 0.4, 0.9, 0.1]) .chartStyle( LineChartStyle(.

SpaceNation 609 Jan 6, 2023
SwiftUI Grid layout with custom styles

SwiftUI Grid SwiftUI Grid view layout with custom styles. Features ZStack based layout Vertical and horizontal scrolling Supports all apple platforms

SpaceNation 928 Dec 15, 2022
Different Styles of Custom Tab Bar

LightCardTabBar An expiremental project exploring different types of custom-tabbar styles, screenshots as below. Screenshots Implementation The implem

Hussein Ryalat 31 Dec 23, 2022
A Custom UIButton with Centralised Styling and common styles available in Interface Builder

DesignableButton DesignableButton is a UIButton subclass that uses a centralised and reusable styling. In InterfaceBuilder, drag and drop a Designable

Idle Hands Apps 93 Aug 14, 2022
Image slide-show viewer with multiple predefined transition styles, with ability to create new transitions with ease.

ATGMediaBrowser ATGMediaBrowser is an image slide-show viewer that supports multiple predefined transition styles, and also allows the client to defin

null 200 Dec 19, 2022
Define UI styles in a hot-reloadable yaml or json file

Stylist ?? Stylist lets you define UI styles in a hot-reloadable external yaml or json theme file ✅ Define styles in external theme files ✅ Apply styl

Yonas Kolb 282 Oct 30, 2022