An elegant alternative to the UIStepper written in Swift

Overview

SnappingStepper

License Supported Plateforms Version Carthage compatible Build Status codecov.io codebeat badge

An elegant alternative to the UIStepper in Swift with a thumb slider addition to control the value update with more flexibility.

screenshot

Usage

let stepper = SnappingStepper(frame: CGRect(x: 0, y: 0, width: 100, height: 40))

// Configure the stepper like any other UIStepper. For example:
//
// stepper.continuous   = true
// stepper.autorepeat   = true
// stepper.wraps        = false
// stepper.minimumValue = 0
// stepper.maximumValue = 100
// stepper.stepValue    = 1

stepper.symbolFont           = UIFont(name: "TrebuchetMS-Bold", size: 20)
stepper.symbolFontColor      = .black
stepper.backgroundColor      = UIColor(hex: 0xc0392b)
stepper.thumbWidthRatio      = 0.5
stepper.thumbText            = ""
stepper.thumbFont            = UIFont(name: "TrebuchetMS-Bold", size: 20)
stepper.thumbBackgroundColor = UIColor(hex: 0xe74c3c)
stepper.thumbTextColor       = .black

stepper.addTarget(self, action: "valueChanged:", forControlEvents: .valueChanged)

// If you don't want using the traditional `addTarget:action:` pattern you can use
// the `valueChangedBlock`
// snappingStepper.valueChangeBlock = { (value: Double) in
//    println("value: \(value)")
// }

func valueChanged(sender: AnyObject) {
  // Retrieve the value: stepper.value
}

To go further, take a look at the example project.

Installation

CocoaPods

Install CocoaPods if not already available:

$ [sudo] gem install cocoapods
$ pod setup

Go to the directory of your Xcode project, and Create and Edit your Podfile and add SnappingStepper:

$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

use_frameworks!
pod 'SnappingStepper', '~> 3.0.0'

Install into your project:

$ pod install

Open your project in Xcode from the .xcworkspace file (not the usual project file):

$ open MyProject.xcworkspace

You can now import SnappingStepper framework into your files.

Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate SnappingStepper into your Xcode project using Carthage, specify it in your Cartfile file:

github "yannickl/SnappingStepper" >= 3.0.0

Swift Package Manager

You can use The Swift Package Manager to install SnappingStepper by adding the proper description to your Package.swift file:

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/yannickl/SnappingStepper.git", versions: "3.0.0" ..< Version.max)
    ]
)

Note that the Swift Package Manager (SPM) is still in early design and development, for more infomation checkout its GitHub Page.

Manually

Download the project and copy the SnappingStepper folder into your project to use it in.

Contribution

Contributions are welcomed and encouraged .

Contact

Yannick Loriot

License (MIT)

Copyright (c) 2015-present - Yannick Loriot

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Removed

    Removed "final" on StyledLabel

    I am creating a new component, which depends on this control and I would like to use the same styling elements in order to have matching styles. The new component needs to derive from the StyledLabel (extension is not adequate), so it would be nice if the "final" declaration is removed from StyledLabel.

    opened by mjrehder 6
  • Added vertical layout option through setting the direction parameter

    Added vertical layout option through setting the direction parameter

    Added the rounded style with corner radius option Updated the example to show the vertical snapper

    With this update, the SnappingStepper can also be used in a vertical layout style. The rounded style with fixed corner radius is required when you want to have the same corner radius among multiple components with different sizes in the UI. I have included the direction enum from MJRFlexStyleComponents in order to ease the layout orientation calculations. The enum is included as-is (public), so that if this PR is accepted and released, then MJRFlexStyleComponents can just use the enum from the SnappingStepper lib.

    If this is acceptable, it would be nice with a new release.

    opened by mjrehder 4
  • Error Rendering SnappingStepper in Storyboard

    Error Rendering SnappingStepper in Storyboard

    > "error: IB Designables: Failed to render instance of SnappingStepper: dlopen(SnappingStepper.framework, 1): Library not loaded: @rpath/DynamicColor.framework/DynamicColor
    >   Referenced from: SnappingStepper.framework
    >   Reason: image not found"
    

    If I use the SnappingStepper in any Storyboard I constantly get the Error Message above...

    opened by imamik 2
  • Hint Label

    Hint Label

    Added a hint label, which can be enabled by setting the showHint property. The hint label is intended to show the changing value while the slider is obscured by the finger when dragging.

    opened by mjrehder 2
  • Update minus sign character

    Update minus sign character

    Use the unicode “minus sign” symbol, instead of the “dash” from the classic keyboard.

    The difference isn’t visible on GitHub, or with most fixed-space fonts, but you can see the result when run on iOS.

    opened by vtourraine 2
  • Swift3

    Swift3

    Small additions and updates to the package.

    • Removal of DynamicColor dependency
    • Add a Number Formatter (optional) for the value label
    • Adjust the default max value
    • Tweak the factor calculation (becomes apparent why it's needed when used with a Number Formatter)
    opened by netizen01 1
  • Cannot import

    Cannot import

    I cannot import SnappingStepper into my project. It is installed via cocoapods just like the other libs. However when I

     import SnappingStepper
    

    It says "cannot load underlaying module for SnappingStepper". I am on swift 2.

    opened by artworkad 1
  • @objc tag for property thumbLabel

    @objc tag for property thumbLabel

    I'd be really great if you could add a @objc tag to the property thumbLabel in your repo so that user defined runtime attributes in Storyboard can be set.

    /// The value label that represents the thumb button
    @objc lazy var thumbLabel: StyledLabel = UIBuilder.defaultStyledLabel()
    

    I have to add it on each pod install manually or else I'm getting a

    [<SnappingStepper.SnappingStepper 0x112209860> valueForUndefinedKey:]: this class is not key value coding-compliant for the key thumbLabel.
    

    Tthanks for your great framework. :)

    opened by RyuX51 0
  • Incremental speed

    Incremental speed

    Hi, thanks for your library. Is it possible to increment the increasing/decreasing speed when continuously pressing the buttons or sliding the thumb? I have a range from 0 to 100, and it takes ages to reach the limit values. I was wondering if you can make the speed exponentially, so the first seconds it's slower then it's faster. Thanks

    opened by Silvia4 0
  • Various fixes and improvements

    Various fixes and improvements

    Summary

    • Using StyledLabel pod
    • Fixed background style masking
    • Fixed symbol label background color issue
    • Added format string
    • Added step factor for value sliding

    Background color issue There was no way to apply a styling with a background color and masking the background to the various styling options. In order to fix this, you need to have a dedicated property for the style color. The property is called styleColor. You can still use the backgroundColor property as before, but it will not mask to the selected style. Most of the work for this fix was already done in the StyledLabel pod (Framework), so I removed the classes from this project and added the framework reference to the podfile.

    Symbol label background After the symbols were pressed, the symbol background was set to backgroundColor (now styleColor), it must be reverted to .clear color.

    Format String In order to correctly format values in the thumb, you must have a way to specify the formatting. This PR introduces the thumbTextFormatString. Default is 'nil', which results in the old behaviour. An example of how bad the UI looks without formatting is by using a [0;1] range with a 0.1 step value and apply sliding. The thumb text will show "0.7239749579" or similar.

    Step Factor When sliding the stepper, then the increase/decrease of the value is fine as long you are operating on integers. A multiplying factor is needed when you have floating point values.

    The examples have been updated to reflect the changes and demonstrations of the new features are included in the examples.

    It would be nice with a new major release of this library, as the current release is based on Swift 2.3 and that version is no longer available in the current Xcode.

    opened by mjrehder 1
  • Compiler Errors

    Compiler Errors

    I would imagine this problem is unique to my setup but as I'm not making any headway on figuring it out, I figure i'd ask.

    Consider the below graphic, dynamic color is throwing all kinds of errors, I also attempted to use the more current dynamic color library but the podfile.lock won't have it. Any thoughts on a possible configuration step I'm missing?

    screenshot 2017-03-05 17 47 55

    opened by jcdavison 0
Owner
Yannick Loriot
iOS developer and nodejs addict. Open-source lover and technology enthusiast.
Yannick Loriot
SMNumberWheel is a subclass of UIControl written in Swift, which is ideal for picking numbers using a rotating wheel.

SMNumberWheel version: 1.0.3 [![CI Status](http://img.shields.io/travis/Sina Moetakef/SMNumberWheel.svg?style=flat)](https://travis-ci.org/Sina Moetak

null 26 Mar 15, 2022
A WeChat alternative. Written in Swift 5.

TSWeChat - A WeChat alternative, updated to Swift 5. 中文说明 Requirements Cocoapods 1.2.0 + iOS 10.0+ / Mac OS X 10.9+ Xcode 10.0+ Features Send your ric

Hilen Lai 3.7k Dec 31, 2022
An alternative gym workouts tracker written in SwiftUI.

Gymspot Gymspot is an alternative workout tracker written in SwiftUI. I decided to start working on it because: I need an easy-to-use tracker for my w

Alessio Moiso 3 Nov 22, 2022
Schedule timing task in Swift using a fluent API. (A friendly alternative to Timer)

Schedule(简体中文) Schedule is a timing tasks scheduler written in Swift. It allows you run timing tasks with elegant and intuitive syntax. Features Elega

Luo Xiu 1.8k Jan 7, 2023
Schedule timing task in Swift using a fluent API. (A friendly alternative to Timer)

Schedule(简体中文) Schedule is a timing tasks scheduler written in Swift. It allows you run timing tasks with elegant and intuitive syntax. Features Elega

Luo Xiu 1.8k Dec 21, 2022
🔸 A customizable alternative to UIPickerView in Swift.

PickerView PickerView is an easy to use and customize alternative to UIPickerView written in Swift. It was developed to provide a highly customizable

Filipe Alvarenga 488 Dec 21, 2022
MZFormSheetPresentationController provides an alternative to the native iOS UIModalPresentationFormSheet, adding support for iPhone and additional opportunities to setup UIPresentationController size and feel form sheet.

MZFormSheetPresentationController MZFormSheetPresentationController provides an alternative to the native iOS UIModalPresentationFormSheet, adding sup

Michał Zaborowski 979 Nov 17, 2022
🔄 GravitySlider is a beautiful alternative to the standard UICollectionView flow layout.

GravitySliderFlowLayout Made by Applikey Solutions Find this project on Dribbble Table of Contents Purpose Supported OS & SDK Versions Installation Us

Applikey Solutions 958 Dec 23, 2022
A modern AppList alternative

AltList A modern AppList alternative The main focus of this dependency is to be an easy to use and easy to customize framework to handle per app prefe

Lars Fröder 59 Jan 2, 2023
An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation.

swiftui-navigation-stack An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations

Matteo 753 Jan 2, 2023
iOS / Objective C: an extremely simple UIAlertView alternative

RKDropdownAlert an extremely simple (and customizeable) alert alternative based on Facebook's app Slingshot, and inspiration from SVProgressHUD (yes,

Richard Kim 1.5k Nov 20, 2022
An alternative to Core Data for people who like having direct SQL access.

FCModel 2 An alternative to Core Data for people who like having direct SQL access. By Marco Arment. See the LICENSE file for license info (it's the M

null 1.7k Dec 28, 2022
An alternative app store for non-jailbroken iOS devices

AltStore AltStore is an alternative app store for non-jailbroken iOS devices. AltStore is an iOS application that allows you to sideload other apps (.

null 1 Dec 9, 2021
ChatLayout is an alternative solution to MessageKit.

ChatLayout is an alternative solution to MessageKit. It uses custom UICollectionViewLayout to provide you full control over the presentation as well as all the tools available in UICollectionView.

Eugene Kazaev 527 Jan 4, 2023
The alternative last.fm client for iOS made with SwiftUI

first.fm - The alternative last.fm client for iOS (it's actually not available on the App Store... yet) Features Your profile (top artists, tracks and

Stanislas 22 Aug 22, 2022
An alternative to UIStackView for common Auto Layout patterns.

StackLayout StackLayout builds on Auto Layout to make some of the most common layouts easier to manage. It creates the constraints that you need and a

Bridger Maxwell 76 Jun 29, 2022
Working alternative to Xcode previews.

SwiftUIPlaygrounds! A shell project you can use to iterate over SwiftUI interfaces using the HotReloading project. Instead of a "preview" the interfac

John Holdsworth 9 Dec 21, 2021
Nicely animated flat design switch alternative to UISwitch

AIFlatSwitch A smooth, nice looking and IBDesignable flat design switch for iOS. Can be used instead of UISwitch. Inspired by Creativedash's Dribbble

null 963 Jan 5, 2023
📱 A minimal tab bar alternative

MiniTabBar A clean simple alternative to the UITabBar. Only shows the title when being tapped on. Gives the app a way cleaner look :) Requirements iOS

Dylan Marriott 155 Dec 20, 2022
● ○ ○ ○ A nice, animated UIPageControl alternative.

Page Control Installation Usage Example import UIKit import PageControl class ViewController: UIViewController, UIScrollViewDelegate { @IBOu

Kasper Lahti 113 Sep 1, 2022