A beautiful slider control for iOS built purely upon Swift

Overview

SnappingSlider

A beautiful slider control for iOS.

Look at that beauty!

Installation

There are two ways to add the control to your project; you can add it as a submodule if you're using GIT as a versioning system or you can install it through CocoaPods. Examples of both are outlined below.

git submodule add https://github.com/rehatkathuria/SnappingSlider

pod "SnappingSlider"

Usage

It's simple, really. In essence, all you need to do is instantiate a slider with a title and conform to the delegate offered.

let slider = SnappingSlider(frame: CGRectMake(0.0, 0.0, 10.0, 10.0), title: "Slide Me")
slider.delegate = self

myAwesomeViewController.view.addSubView = slider


...


func snappingSliderDidIncrementValue(snapSwitch: SnappingSlider) {

}

func snappingSliderDidDecrementValue(snapSwitch: SnappingSlider) {

}

Author

This control has been open-sourced by Rehat Kathuria. You can follow him on twitter, here, and hire him for freelance projects, here.

License & Other Boring Stuff

Licensed under MIT. If you use the control somewhere, do let me know. I'd love to see it out in the wild.

Comments
  • Hold Slider Down To Increment/Decrement Values

    Hold Slider Down To Increment/Decrement Values

    I've been toying with the idea of allowing the slider to continue incrementing or decrementing the value until the user releases the touch from the slider. This functionality could be toggled with a boolean. What does the community think? Would you guys like to see this?

    cc @ashfurrow.

    enhancement 
    opened by rehatkathuria 5
  • changing position of slider.

    changing position of slider.

    Hi: thanks for the great slider. I am using it in my app. I have one slight issue. I cant seem to change the code to move it to the top of my app. No matter which CGrect I change the slider is always in the center vertically and horizontally. Any help would be greatly appreciated.

    opened by keji96 4
  • Adding Slider into TableViewCell failed to fit the size of the screen

    Adding Slider into TableViewCell failed to fit the size of the screen

    I called this in my override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell function:

    let QuantitySlider = SnappingSlider(frame: CGRectMake(0.0, 0.0, 10.0, 10.0), title: "Quantity")
            QuantitySlider.translatesAutoresizingMaskIntoConstraints = false
            cell.QuantitySliderView.addSubview(QuantitySlider)
            QuantitySlider.delegate = self
    
            QuantitySlider.frame = CGRectMake(0.0, 0.0, cell.QuantitySliderView.bounds.size.width * 0.5, 50.0)
            QuantitySlider.center = CGPointMake(cell.QuantitySliderView.bounds.size.width * 0.5, cell.QuantitySliderView.bounds.size.height * 0.5)
    

    However, the slider doesn't seem to come in the right place. I also added

    print(QuantitySlider.bounds)
    print(cell.QuantitySliderView.bounds) 
    

    in my method, and the result is (0.0, 0.0, 258.0, 50.0) (0.0, 0.0, 516.0, 68.0)

    I try to fix the screen in my storyboard in to 5.5 inch iPhone size, and the result is around (0.0, 0.0, 167.0, 50.0) (0.0, 0.0, 334.0, 68.0)

    I think this is where the problem is. By the way, my QuantitySliderView has constraints that keep it in the center of the cell, so it is not the case that my QuantitySliderView has problem. Please respond, thank you!

    opened by Zarjagen 2
  • New issue with cocoapods

    New issue with cocoapods

    When trying to install I get this issue:

    [!] /usr/local/bin/git clone https://github.com/rehatkathuria/SnappingSlider.git /var/folders/kr/n3d8ggbd71j7zsl3h52pdqy40000gn/T/d20160914-5188-15j253k --template= --single-branch --depth 1 --branch 1.1

    Cloning into '/var/folders/kr/n3d8ggbd71j7zsl3h52pdqy40000gn/T/d20160914-5188-15j253k'... warning: Could not find remote branch 1.1 to clone. fatal: Remote branch 1.1 not found in upstream origin

    opened by andreichirkunovgoon 1
  • Need Help: Automatically resets when changing the text of UILabel

    Need Help: Automatically resets when changing the text of UILabel

    Thanks for your beautiful slider, I'm using it for my Swift class assignment.

    Here's my question:

    When I tried to build something just like your demo GIF, where the slider controls the text of the UILabel, I found it quite difficult to make one. Since I had to use auto layout for adaptivity, I had a UIView to contain the slider. I wrote some lines of codes based on your given 'Usage' example, and I found it unable to control the text of the UILabel. When I tried to move the slider, it just reset itself to the initiate state while not change a thing. however, it was not completely not working since it run smoothly if I just wrap some print command in the function.

    P.S., I found that there is some unexpected part of the slider (color is the same as the middle of the slider) on the right padding of the UIView, and I drew CGRect to cover it up. Hope there is a better way to avoid this.

    Here's my code of the ViewController.

    import UIKit
    import SnappingSlider
    
    class ViewController: UIViewController, SnappingSliderDelegate {
    
        @IBOutlet weak var sliderView: SliderView!
        @IBOutlet weak var hoursLabel: UILabel!
    
        override func viewDidLayoutSubviews() {
            let sliderLength = sliderView.frame.size.width
            let sliderWidth = sliderView.frame.size.height
            let slider = SnappingSlider(frame: CGRectMake(0.0, 0.0, sliderLength, sliderWidth), title: "Working Time")
            slider.delegate = self
            let sliderMask = UIView(frame: CGRectMake(sliderLength,0.0,40,50))          // sliderMask is used to cover the unexpected part
            sliderMask.backgroundColor=UIColor.whiteColor()
            sliderView.addSubview(slider)
            sliderView.addSubview(sliderMask)
            hoursLabel.text = "3"
        }
    
        func hoursChange(symbol: String) {
            let a = Int(hoursLabel.text!)!
            let b = 1
            if symbol == "+" {
                hoursLabel.text = "\(a+b)"
    //            print("\(a+b)")                           // run smoothly if the previous line is commented while this line is not commented
            } else if symbol == "-" {
                hoursLabel.text = "\(a-b)"
    //            print("\(a-b)")                           // run smoothly if the previous line is commented while this line is not commented
            }
        }
    
        func snappingSliderDidIncrementValue(snapSwitch: SnappingSlider) {
            hoursChange("+")
        }
    
        func snappingSliderDidDecrementValue(snapSwitch: SnappingSlider) {
            hoursChange("-")
        }
    }
    

    Thanks for your help!

    opened by wakune 1
  • Enhancement

    Enhancement

    Hey, I really like this control! One thing I could see being useful, is making the decrease/increase labels into buttons instead. To allow for precision.

    opened by johnrickman 1
  • add 3 smappinslider

    add 3 smappinslider

    hello how can add 3 smappinslider and func snappingSliderDidIncrementValue(snapSwitch: SnappingSlider) ,func snappingSliderDidDecrementValue(snapSwitch: SnappingSlider) ??

    opened by J-Arji 0
  • Code cleanup.

    Code cleanup.

    Hey!

    So I took a quick look through and saw some opportunities to be more idiomatic with Swift. The big ones are:

    • Makes things public for use inside Frameworks.
    • Removes a bunch of self.
    • Removes unnecessary explicit type declarations on properties.
    • Removes setting variable to default, private value in initializer (uses defaults on declarations instead).
    • Uses didSet to inject side-effects.

    I noticed you're setting a lot of frames, then centers. This is usually not necessary – setting frame is actually shorthand for setting the bounds.size and the centre. If you'd like to continue doing so, that's cool. There're methods like CGRectGetMidX() that can be used instead of bounds.size.width * 0.5, too.

    opened by ashfurrow 0
  • error in insert

    error in insert

    hello when i insert SnappingSliderDelegate error Use of undeclared type 'SnappingSliderDelegate' and when that import SnappingSlider error : No such module 'SnappingSlider'

    opened by J-Arji 1
Owner
Rehat Kathuria
Rehat Kathuria
PhotoSlider is a simple photo slider and can delete slider with swiping.

PhotoSlider is a simple photo slider and can delete slider with swiping.

Daichi Nakajima 247 Nov 30, 2022
VerticalSlider is a vertical slider control for iOS in Swift.

?? VerticalSlider If you like VerticalSlider, give it a ★ at the top right of this page. Overview VerticalSlider is a vertical implementation of the U

Jon Kent 78 Sep 15, 2022
This is an iOS Tweak that modifies the brightness slider in the Control Center.

AdvancedBrightnessSlider Tweak This is an iOS Tweak that modifies the brightness slider in the Control Center. Even with dark mode toggled on, I found

Jonas Schiefner 18 Jan 5, 2023
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
iOS 11 Control Center Slider

SectionedSlider Control Center Slider Requirements Installation Usage License Requirements iOS 8.0+ Swift 3.0+ Xcode 8.0+ Installation CocoaPods Cocoa

Leonardo Cardoso 361 Dec 3, 2022
A feature-rich circular slider control written in Swift.

MTCircularSlider Screenshot Usage To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 1

Eran Boudjnah 132 Jan 1, 2023
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
FlowerSlider - Flower Slider Animation Built With Swift

FlowerSlider Shape Slider Screenshot

Joey Graham 4 Sep 27, 2022
An iOS Slider written in Swift.

JDSlider Beetripper App's screenshots Example Project To run the example project, clone the repo, and run pod install from the Example directory first

Jelly Development 84 Jul 26, 2022
Use UIResponder to imitate an iOS slider.

WWSlider Use UIResponder to imitate an iOS slider. 使用UIResponder仿造一個iOS的滑桿. Installation with Swift Package Manager dependencies: [ .package(url:

William-Weng 2 May 5, 2022
Customizable animated slider for iOS

MMSegmentSlider MMSegmentSlider is an easy-to-use IBDesignable animated slider for iOS 7+ written in Objective-C. Installation From CocoaPods CocoaPod

Max Medvedev 48 Jul 26, 2022
Customizable animated slider for iOS

MMSegmentSlider MMSegmentSlider is an easy-to-use IBDesignable animated slider for iOS 7+ written in Objective-C. Installation From CocoaPods CocoaPod

Max Medvedev 48 Jul 26, 2022
An iOS-16-styled slider.

Slyderin An iOS-16-styled slider. Available on iOS 13 and later. Slyderin.Demo.mov How to Use Include it with Swift Package Manager. Add it to your vi

iMoeNya 3 Jan 1, 2023
IntervalSlider is a slider library like ReutersTV app. written in pure swift.

IntervalSlider Description and appetize.io`s DEMO To run the example project, clone the repo, and run pod install from the Example directory first. Re

Nobuyasu 65 May 23, 2021
A simple range slider made in Swift

RangeSlider Summary A simple range slider made in Swift. Screenshot Use This control is IBDesignable and uses the target-action pattern for change not

William Archimede 305 Nov 29, 2022
CircleSlider is a Circular slider library. written in pure Swift.

CircleSlider Description and appetize.io`s DEMO Usage To run the example project, clone the repo, and run pod install from the Example directory first

Nobuyasu 142 May 9, 2022
A powerful Circular Slider. It's written in Swift, it's 100% IBDesignable and all parameters are IBInspectable.

CircularSlider A powerful Circular Slider. It's written in Swift, it's 100% IBDesignable and all parameters are IBInspectable. Demo Installation Circu

Matteo Tagliafico 253 Sep 19, 2022
💧 A slider widget with a popup bubble displaying the precise value selected. Swift UI library made by @Ramotion

FLUID SLIDER A slider widget with a popup bubble displaying the precise value selected written on Swift. We specialize in the designing and coding of

Ramotion 1.9k Dec 23, 2022
VerticalSlider - An animatable and customizable vertical slider written in Swift 4

VerticalSlider An animatable and customizable vertical slider written in Swift 4. Quick Start VerticalSliderPlayground Clone Repo Open VSVerticalSlide

Vincent Smithers 13 Apr 26, 2022