Coder Social home page Coder Social logo

valuestepper's Introduction

ValueStepper

CI Status 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 the 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
    
/// 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
    
/// Describes the format of the value.
public var numberFormatter: NSNumberFormatter
    
// 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

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 2.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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.