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 was initially created in Objective-C for Addo Label's Counters• and is now available in Swift for you to enjoy :)
- 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.
KWStepper is available through CocoaPods. To install
it, simply add the following lines to your Podfile
:
platform :ios, '8.0'
use_frameworks!
pod 'KWStepper'
To integrate KWStepper using Carthage, add the following line to you Cartfile
:
github "kyleweiner/KWStepper"
If you prefer not to use a dependency manager, simply copy the Source/KWStepper.swift
file into your project.
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 = { [unowned self] stepper in
self.countLabel.text = String(format: "%.f", stepper.value)
}
Or, use the target-action pattern.
stepper.addTarget(self, action: "stepperDidChange", forControlEvents: .ValueChanged)
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
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 present a UIAlertController
when a limit is reached and the wraps
property is set to false
.
KWStepper provides the following callbacks:
valueChangedCallback
decrementCallback
incrementCallback
maxValueClampedCallback
minValueClampedCallback
In the example project, valueChangedCallback
is used to update the count label text when the stepper value changes.
KWStepper was written by Kyle Weiner.
KWStepper is available under the MIT license. See the LICENSE file for details.