A Stepper object that displays its value.

Overview

ValueStepper

Carthage compatible Version License Platform

Description

ValueStepper is an improved replication of Apple's UIStepper object. The problem with UIStepper is that it doesn't display the value to the user. I was tired of creating a simple UILabel just to show the value in the UI. ValueStepper integrates the value in a UILabel between the increase and decrease buttons. It's as easy as that.

Usage

To see it in action, run the example project, clone the repo, and run pod install from the Example directory first. The example project shows how to set up ValueStepper in Storyboard.

Storyboard

Drag a UIView object and set the class to ValueStepper (if needed set the module to ValueStepper too). You can now customize all the properties in IB such as the minimumValue, tintColor and so on. Make sure to set the width to 149 and the height to 29 which are the default values. Create an @IBAction on the ValueChanged control event to be notified when the value changes.

Programmatically

import ValueStepper

let valueStepper: ValueStepper = {
    let stepper = ValueStepper()
    stepper.tintColor = .whiteColor()
    stepper.minimumValue = 0
    stepper.maximumValue = 1000
    stepper.stepValue = 100
    return stepper
}()

override func viewDidLoad() {
    super.viewDidLoad()       
    valueStepper.addTarget(self, action: "valueChanged:", forControlEvents: .ValueChanged)
}

@IBAction func valueChanged1(sender: ValueStepper) {
    // Use sender.value to do whatever you want
}

Customizations

These are the available properties with the relative documentation.

/// Current value and sends UIControlEventValueChanged when modified.
@IBInspectable public var value: Double = 0.0
    
/// Minimum value that must be less than the maximum value.
@IBInspectable public var minimumValue: Double = 0.0 
    
/// Maximum value that must be greater than the minimum value.
@IBInspectable public var maximumValue: Double = 1.0
    
/// When set to true, the user can tap the label and manually enter a value.
@IBInspectable public var enableManualEditing: Bool = false
    
/// The value added/subtracted when one of the two buttons is pressed.
@IBInspectable public var stepValue: Double = 0.1
    
/// When set to true, keeping a button pressed will continuously increase/decrease the value every 0.1s.
@IBInspectable public var autorepeat: Bool = true

/// The background color of the stepper buttons while pressed.
@IBInspectable public var highlightedBackgroundColor: UIColor = UIColor(white: 1.0, alpha: 0.1)

/// The color of the +/- icons when in disabled state.
@IBInspectable public var disabledIconButtonColor: UIColor = UIColor.gray

/// The color of the +/- buttons background when in disabled state.
@IBInspectable public var disabledBackgroundButtonColor: UIColor = UIColor.clear

/// The background color of the plus and minus buttons.
@IBInspectable public var backgroundButtonColor: UIColor = UIColor.clear
    
/// The background color of the center view that contains the value label.
@IBInspectable public var backgroundLabelColor: UIColor = UIColor.clear
    
/// The text color of the value label in positioned in the center.
@IBInspectable public var labelTextColor: UIColor = UIColor.white
    
/// Describes the format of the value.
public var numberFormatter: NumberFormatter
    
// Default width of the stepper. Taken from the official UIStepper object.
public let defaultWidth = 141.0
    
// Default height of the stepper. Taken from the official UIStepper object.
public let defaultHeight = 29.0

/// Value label that displays the current value displayed at the center of the stepper.
public let valueLabel: UILabel

Installation

ValueStepper is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ValueStepper'

You can also use Carthage if you prefer. Add this line to your Cartfile.

github "BalestraPatrick/ValueStepper"

Requirements

iOS 8.3 and Swift 4.0 are required.

Author

I'm Patrick Balestra. Email: [email protected] Twitter: @BalestraPatrick.

License

ValueStepper is available under the MIT license. See the LICENSE file for more info.

Inspired by GMStepper. Thanks to Gmertk for the interesting and useful related blog post.

Comments
  • changing tint color of stepper doesn't update the decrease/increate layer (- / +)

    changing tint color of stepper doesn't update the decrease/increate layer (- / +)

    I have put the stepper in a tableViewCell, and for testing purposes every time the cell is show, the tint color is chosen randomly so, so once they go out of view, and come back they will have new color. screen shot 2017-01-26 at 1 33 38 pm After coming back into view. screen shot 2017-01-26 at 1 34 01 pm

    fix would be to add these into func tintColorDidChange()

    increaseLayer.strokeColor = tintColor.cgColor
    decreaseLayer.strokeColor = tintColor.cgColor
    
    opened by skibadawid 6
  • Build Error - Shared is unavailable

    Build Error - Shared is unavailable

    I installed using Pod as indicated. Made no changes and instantly had the error. "Shared" is unavailable. Use New Controller based solution.

    Using Xcode 8.3.3. Thanks for your help! Howard

    opened by hsmith825 4
  • Not able to get tag for Decrement Button.

    Not able to get tag for Decrement Button.

    /// - decrease: decrease button has tag 0. /// - increase: increase button has tag 1. private enum Button: Int { case decrease case increase }

    You can not set the tag value of an element to 0. Need to modify that logic in order to get elements by tag value correctly.

    /// - decrease: decrease button has tag 1. /// - increase: increase button has tag 2. private enum Button: Int { case decrease = 1 case increase = 2 }

    opened by dhavalbarot 3
  • Don't return early from increase/decrease functions when auto repeat is enabled

    Don't return early from increase/decrease functions when auto repeat is enabled

    The return statement on lines 255 and 265 prevent a normal tap from changing the value and forces the user to tap+hold to change the value when autorepeat is enabled. Removing these two lines will cause the control to behave like the standard UIStepper where a tap+release will change the value by the step amount exactly once and a tap+hold will still autorepeat the value change.

    opened by gcox 2
  • Added NSNumberFormatter for easier number formatting

    Added NSNumberFormatter for easier number formatting

    Fixed #1

    It's now possible to customize or provide a NSNumberFormatter object in this way:

    let moneyFormatter = NSNumberFormatter()
    moneyFormatter.numberStyle = .CurrencyStyle
    moneyFormatter.maximumFractionDigits = 0
    stepper.numberFormatter = moneyFormatter
    

    Or simply modify the default NSNumberFormatter:

    stepper3.numberFormatter.maximumFractionDigits = 1
    
    opened by BalestraPatrick 2
  • Bug in labelPressed function

    Bug in labelPressed function

    There is a subtle bug in labelPressed function on line 360. The following line of code if newValue >= self.minimumValue || newValue <= self.maximumValue must be replaced by if newValue >= self.minimumValue && newValue <= self.maximumValue

    The || operator must be replaced by && operator.

    opened by savyasachi 1
  • Dependency

    Dependency "ValueStepper" has no shared framework schemes

    Hi I am receiving this error when updating Carthage. Can you help?

    *** Skipped building ValueStepper due to the error: Dependency "ValueStepper" has no shared framework schemes

    Thanks WTBM

    opened by WTBM 1
  • Add properties to customize button colors

    Add properties to customize button colors

    What's in this PR?

    I started using this component in a small side project and was in need for a bit more customization.

    • Add disabledButtonColor which can be used to set a custom color used by the +/- buttons when they are disabled and no input is possible.
    • Add highlightedBackgroundColor which can be used to set a custom background color for the +/- buttons which was defaulting to .gray which might not be desired when using the stepper on brighter brackgrounds.
    • Add another stepper to the example project showcasing the added color properties.
    opened by daehn 1
  • fix to when valueStepper is in a tableViewCell, autorepeat = true, and press on +/- after scrolling

    fix to when valueStepper is in a tableViewCell, autorepeat = true, and press on +/- after scrolling

    fix to #13 (a noob here so do I need to create an issue first and then do a PR?)

    this part of code fixes issue where incrementing/decrementing is in infinite loop and when pressed + or - stops the it, attached a gif. also removes redundant continuousTimer?.invalidate() calls that can be replaced with continuousTimer = nil

    private var continuousTimer: Timer? {
        didSet {
            if let timer = oldValue {
                timer.invalidate()
            }
        }
    }
    

    bug_semi_fix

    Adding an event action .touchCancel fixed the issue with infinite increment/decrement. choose to add it to decrease()/increate selector so its responsive to user interaction, but could be attached to the stopContinuous of increase and decrease button. [around line 140]

    decreaseButton.addTarget(self, action: #selector(decrease(_:)), for: [.touchUpInside, .touchCancel])
    increaseButton.addTarget(self, action: #selector(increase(_:)), for: [.touchUpInside, .touchCancel])
    
    
    opened by skibadawid 1
  • Fixed bug with inability to select maximum and minimum values

    Fixed bug with inability to select maximum and minimum values

    In current version increase and decrease buttons becomes disabled when _value ± stepValue ≥≤ max/min, but condition **equal**_ means what we can perform one more step.

    opened by ifau 1
  • Fix broken headings in Markdown files

    Fix broken headings in Markdown files

    GitHub changed the way Markdown headings are parsed, so this change fixes it.

    See bryant1410/readmesfix for more information.

    Tackles bryant1410/readmesfix#1

    opened by bryant1410 0
  • INCREMENT / DECREMENT

    INCREMENT / DECREMENT

    Hello, please add a callback If user Increment or decrement it would be a lot easier for us thanks, because for now we need to store the previous value to check if it's +1 / - 1

    opened by Dave181295 1
  • 'shared' is unavailable in application extensions for iOS

    'shared' is unavailable in application extensions for iOS

    image

    Pod library is not working for extension, I tried to set Require only app-extension-safe api to NO, but didn't work. I am using the extension for remote notification. Please let me know if there is any workaround

    opened by abhinav-Milezero 0
  • Multiple ValueStepper Used in CollectionView keeps calling target function

    Multiple ValueStepper Used in CollectionView keeps calling target function

    When we use ValueStepper in collectionView Cell, every time reusable cell is allocated, ValueStepper calls target method even though when it is not required. Also when altering value of the stepper, target method is called. What I think is you can remove Action(for:) from DidSet of value variable.

    opened by perinpatel 0
  • Error on compilation

    Error on compilation

    ValueStepper.swift line 205

    override open static var requiresConstraintBasedLayout: Bool 
    

    produces error:

    Static declarations are implicitly 'final'; use 'public' instead of 'open'

    opened by nick-iCars 1
Releases(1.6)
Owner
Patrick Balestra
Infra Engineer at @spotify. Previously at @n26, @Scandit, BCG DV and FIFA TMS.
Patrick Balestra
LabeldStepper - A native SwiftUI stepper that shows the current value and has more features

LabeledStepper A native SwiftUI Stepper that shows the value with more features!

Seyed Mojtaba Hosseini Zeidabadi 10 Nov 2, 2022
May be the most elegant stepper you have ever had!

PFStepper It may be the most elegant stepper you have ever had! Usage To be written. Todo Documenting @IBDesignable supporting Animations Customizable

null 25 Dec 16, 2019
A stepper with a sliding label in the middle.

GMStepper A stepper with a sliding label in the middle. Pan the label or tap the buttons. Check out the tutorial, How to Build a Custom Stepper - Part

Günay Mert Karadoğan 916 Dec 18, 2022
SuperStepper - Super Stepper in SwiftUI

SuperStepper Example To run the example project, clone the repo, and run pod ins

Chanwoo Cho 15 Sep 7, 2022
Stepper-View - Stepper view using with UICollectionView with Custom animation & Transation

Stepper view using with UICollectionView with Custom animation & Transation. ??

mohamed gamal 3 Jun 28, 2022
An Integer type that clamps its value to its minimum and maximum instead of over- or underflowing.

ClampedInteger An Integer type that clamps its value to its minimum and maximum instead of over- or underflowing. Examples let big = ClampedIntege

Berik Visschers 0 Jan 17, 2022
LabeldStepper - A native SwiftUI stepper that shows the current value and has more features

LabeledStepper A native SwiftUI Stepper that shows the value with more features!

Seyed Mojtaba Hosseini Zeidabadi 10 Nov 2, 2022
UIView subclass that bends its edges when its position changes.

AHKBendableView BendableView is a UIView subclass that bends its edges when its position change is animated. Internally, BendableView contains CAShape

Arek Holko 591 Jul 24, 2022
A UISwitch that infects its superview with its tint color.

UISwitch subclass that 'infects' the parent view with the onTintColor when the switch is turned on. Inspired by this Dribble by Ramotion. Screenshot I

Andrea Mazzini 337 Sep 12, 2022
A navigation controller that displays its view controllers as an interactive stack of cards.

CardNavigation The easiest way to turn a navigation controller into an interactive stack of cards. Highlights ✅ Fully interactive and interruptible ✅

James Randolph 41 Sep 29, 2022
A UICollectionViewLayout subclass displays its items as rows of items similar to the App Store Feature tab without a nested UITableView/UICollectionView hack.

CollectionViewShelfLayout A UICollectionViewLayout subclass displays its items as rows of items similar to the App Store Feature tab without a nested

Pitiphong Phongpattranont 374 Oct 22, 2022
Animate numeric value while setting new value to label

NumericAnimatedLabel Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installati

Javal Nanda 28 Oct 11, 2021
A UISlider subclass that displays the slider value in a popup view

ASValueTrackingSlider ###What is it? A UISlider subclass that displays live values in an easy to customize popup view. ![screenshot] (http://alskipp.g

Al Skipp 1.8k Dec 16, 2022
A swift package(SPM) with iOS UI component that loads and displays images from remote urls or local assets and displays in a slide-show form with auto scroll feature.

MDBannersView A swift package with an iOS UI component that loads and displays images from remote urls, local assets and displays in a slide-show form

Madhav Deva 2 Feb 5, 2022
A stepper with a sliding label in the middle.

GMStepper A stepper with a sliding label in the middle. Pan the label or tap the buttons. Check out the tutorial, How to Build a Custom Stepper - Part

Günay Mert Karadoğan 916 Dec 18, 2022
SwiftUI library to create fully customizable input stepper.

SwiftUI-InputStepper Swift package for creating numerical input stepper. An example of input stepper created with this library It supports long press

Mateusz Budnik 4 Nov 2, 2022
May be the most elegant stepper you have ever had!

PFStepper It may be the most elegant stepper you have ever had! Usage To be written. Todo Documenting @IBDesignable supporting Animations Customizable

null 25 Dec 16, 2019
A stepper with a sliding label in the middle.

GMStepper A stepper with a sliding label in the middle. Pan the label or tap the buttons. Check out the tutorial, How to Build a Custom Stepper - Part

Günay Mert Karadoğan 916 Dec 18, 2022
SuperStepper - Super Stepper in SwiftUI

SuperStepper Example To run the example project, clone the repo, and run pod ins

Chanwoo Cho 15 Sep 7, 2022
Decodable Simple and strict, yet powerful object mapping made possible by Swift 2's error handling.

Decodable Simple and strict, yet powerful object mapping made possible by Swift 2's error handling. Greatly inspired by Argo, but without a bizillion

Johannes Lund 1k Jul 15, 2022