Giter VIP home page Giter VIP logo

kwstepper's Introduction

KWStepper

Version License Platform

KWStepper is a stepper control written in Swift. Unlike UIStepper, KWStepper allows for a fully customized UI and provides callbacks for tailoring the UX.

KWStepper Screenshot

KWStepper was initially created in Objective-C for Addo Label's Counters• and is now available in Swift for you to enjoy :)

Features

  • Allows for a fully customized UI.
  • Provides properties for setting different decrement and increment steps.
  • Offers optional callbacks for responding to control events and tailoring the UX.

Installation

CocoaPods

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

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'KWStepper'

Manually

If you prefer not to use a dependency manager, simply copy the Source/KWStepper.swift file into your project.

Usage

Try the example project!

var stepper: KWStepper!

@IBOutlet weak var countLabel: UILabel!
@IBOutlet weak var decrementButton: UIButton!
@IBOutlet weak var incrementButton: UIButton!
stepper = KWStepper(
    decrementButton: decrementButton,
    incrementButton: incrementButton)

Respond to control events using the valueChangedCallback property.

stepper.valueChangedCallback = {
    self.countLabel.text = NSString(format: "%.f", self.stepper.value)
}

Or, use the target-action pattern.

stepper.addTarget(self,
    action: "stepperDidChange",
    forControlEvents: .ValueChanged)
func stepperDidChange() {
    countLabel.text = NSString(format: "%.f", stepper.value)
}

Configuring KWStepper

With the exception of the continuous property, KWStepper offers everything provided by UIStepper and more.

stepper.autoRepeat = true
stepper.autoRepeatInterval = 0.10
stepper.wraps = true
stepper.minimumValue = 0
stepper.maximumValue = 8
stepper.value = 0
stepper.incrementStepValue = 1
stepper.decrementStepValue = 1

KWStepperDelegate

Adopting KWStepperDelegate provides the following optional delegate methods for tailoring the UX.

  • optional func KWStepperDidDecrement()
  • optional func KWStepperDidIncrement()
  • optional func KWStepperMaxValueClamped()
  • optional func KWStepperMinValueClamped()

In the example project, KWStepperMaxValueClamped() and KWStepperMinValueClamped() are used to show a UIAlertView when a limit is reached and the wraps property is set to false.

In Counters•, KWStepperDidDecrement() and KWStepperDidIncrement() are used to play different sounds when decrementing and incrementing the steppers.

Callbacks

As an alternative to the KWStepperDelegate protocol, KWStepper provides the following callbacks:

  • valueChangedCallback
  • decrementCallback
  • incrementCallback
  • maxValueClampedCallback
  • minValueClampedCallback

Author

KWStepper was written by Kyle Weiner.

License

KWStepper is available under the MIT license. See the LICENSE file for details.

kwstepper's People

Contributors

kyleweiner avatar

Watchers

 avatar

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.