Git Product home page Git Product logo

gmstepper's Introduction

GMStepper

Version License Platform

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

Screenshot

Screenshot_1.gif

Usage

GMStepper is available through CocoaPods and Swift Package Manager.

Cocoapods

To install using Cocoapods, simply add the following lines to your Podfile:

use_frameworks!
pod "GMStepper"

Swift Package Manager

To install using Swift Package Manager in XCode:

Setup

If you want to use storyboards, just drop a UIView into your storyboard and set its class to GMStepper. Then customize through the attributes inspector. Otherwise, you can write the code to initialize with frame and set the properties.

Properties

/// Current value of the stepper. Defaults to 0.
var value: Double = 0

/// Minimum value. Must be less than maximumValue. Defaults to 0.
var minimumValue: Double = 0

/// Maximum value. Must be more than minimumValue. Defaults to 100.
var maximumValue: Double = 100

/// Step/Increment value as in UIStepper. Defaults to 1.
var stepValue: Double = 1

/// The same as UIStepper's autorepeat. If true, holding on the buttons or keeping the pan gesture alters the value repeatedly. Defaults to true.
var autorepeat: Bool = true

/// If the value is integer, it is shown without floating point.
var showIntegerIfDoubleIsInteger: Bool = true

/// Text on the left button. Be sure that it fits in the button. Defaults to "-".
var leftButtonText: String = "-"

/// Text on the right button. Be sure that it fits in the button. Defaults to "+".
var rightButtonText: String = "+"

/// Text color of the buttons. Defaults to white
var buttonsTextColor: UIColor = UIColor.whiteColor()

/// Background color of the buttons. Defaults to dark blue.
var buttonsBackgroundColor: UIColor = UIColor(red:0.21, green:0.5, blue:0.74, alpha:1)

/// Font of the buttons. Defaults to AvenirNext-Bold, 20.0 points in size.
var buttonsFont = UIFont(name: "AvenirNext-Bold", size: 20.0)

/// Text color of the middle label. Defaults to white.
var labelTextColor: UIColor = UIColor.whiteColor()

/// Text color of the middle label. Defaults to lighter blue.
var labelBackgroundColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)

/// Font of the middle label. Defaults to AvenirNext-Bold, 25.0 points in size.
var labelFont = UIFont(name: "AvenirNext-Bold", size: 25.0)

/// Corner radius of the middle label's layer. Defaults to 0.0.
var labelCornerRadius: CGFloat = 0.0

/// Corner radius of the stepper's layer. Defaults to 4.0.
var cornerRadius: CGFloat = 4.0

/// Border width of the stepper and middle label's layer. Defaults to 0.0.
var borderWidth: CGFloat = 0.0

/// Color of the border of the stepper and middle label's layer. Defaults to clear color.
var borderColor: UIColor = UIColor.clearColor()

/// Percentage of the middle label's width. Must be between 0 and 1. Defaults to 0.5. Be sure that it is wide enough to show the value.
var labelWidthWeight: CGFloat = 0.5

/// Color of the flashing animation on the buttons in case the value hit the limit.
var limitHitAnimationColor: UIColor = UIColor(red:0.26, green:0.6, blue:0.87, alpha:1)

Authors

License

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

gmstepper's People

Contributors

bwhtmn avatar gmertk avatar legoless avatar lexrus avatar luugiathuy avatar noobs2ninjas avatar shamsmosowi avatar sk-chanch avatar vtourraine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gmstepper's Issues

Allow "timerFireCountModulo" to be changed

Hey,

It would be great if you would expose and make the var timerFireCountModulo: Int into a property which we can change. Currently it's a get-only property.

I'd like to remove the "the longer you hold, the faster it'll change the value" functionality and just make it increment based on my custom value (which in this case would be 2. From your comments: // 0.05 sec * 2 = 0.1 sec). That would be the ideal speed for me.

Thanks

Should the GMStepper class be open?

In order for other people to be able to subclass the GMStepper easily and override the setup() method, should the GMStepper class be open?

Swift 2.0

I get build errors on Swift 2. Can you make a branch for it? Thank you!

How to know which button tapped Plus or Minus

Is there any way by which can we know that which button tapped Plus(+) or Minus(-).
I want to perform specific action when user tapped Minus(-). I have made action of stepper like this:

@IBAction func stepper_Item_Tapped(_ sender: GMStepper) {
    //
}

it will be much better if it was a textfield not a label !

Hi ,
Just I want to say it will be much better if it was a textfield not a label !

why ?

because user can click on the textfield to change numbers using keyboard
if the number he's want was bigger

it will be useless clicking on "+" button until reach it !

reset() causing crash

func setup() {
    addSubview(leftButton)
    addSubview(rightButton)
    addSubview(label)

    backgroundColor = buttonsBackgroundColor
    layer.cornerRadius = cornerRadius
    clipsToBounds = true

    //Commented this line out
    NotificationCenter.default.addObserver(self, selector: #selector(GMStepper.reset), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
}

Whenever the applicationWillResignActive AppDelegate function was being called, the reset() function would cause a 'found nil while unwrapping an optional value' error. Not sure why the steppers need to be reset when the application resigns, honestly. I commented the observer out and it seems to work fine. If I'm wrong in this, or there's a better way to fix this error, please do inform me. Thanks!

Stepper value changed from 1

I hace setup GMStepper in my UITableViewCell. In cellForRowAt indexPath method I am setting its textlable value like this:
cell.stepper.label.text = String(receive_Cart[indexPath.row].quantity)
value is displaying correctly.

But when I changed its value by + or - it is not changing relative to value which I set in cellForRowAt indexPath.

Example: The stepper label is set to 3. I have press + it should display 4 but it is displaying 2

I have made a delegate of cell and function for stepper:

func stepperValueChanged(cell: CartCell) {

    }

Cannot add GMStepper to a TableViewCell nib

When I add this to a .xib file for a UITableViewCell, it does not show up. It does show up when I add it to a view in a storyboard. It is odd that the stepper will not show when added to a contentView in a UITableViewCell xib. The xib file uses size classes and auto layout, just like storyboards. I do not understand why this is not working...

Button Modifications

Can we modify buttons ( ie. assigning different colors or custom images to buttons) ?

Argument labels '(stringInterpolationSegment:)' do not match any available overloads

Hi, I upgraded my application from Swift 4.2 to Swift 5 and I get an error. How do i fix this?

File: GMStepper.swift

Error: Argument labels '(stringInterpolationSegment:)' do not match any available overloads

Error is in 2 areas.

Area 1:

else if isInteger {
label.text = String(stringInterpolationSegment: "(Int(value))(self.suffixString)"/Int(value)/)
}
else {
label.text = String(stringInterpolationSegment: "(value)(self.suffixString)"/value/)
}

Area 2:

if self.showIntegerIfDoubleIsInteger && floor(self.value) == self.value {
label.text = String(stringInterpolationSegment: "(Int(self.value))(self.suffixString)")
} else {
label.text = String(stringInterpolationSegment: "(Int(self.value))(self.suffixString)")
}

GMStepper for iOS 7

Hey Günay, thank you for sharing this. It's really impressive work you've done. I'm interested in including your stepper in a project I am currently working on.

Is it possible you would in the nearest future patch this up for iOS 7? Thank you once again.

Double rounding

First of all, nice library!
I use it in my (production) app, and i really enjoy it.
However today i noticed a strange behavior. Lets say the step value is setted to 0.1. Lets also say the stepper goes from 3.0 to 7.5. If autorepeat enabled, and user presses on the stepper for long time, the double gets rounded to (for example) 5.1000000000001 . This happens only when the maximum velocity of long pressing is reached.
I was able to solve it using a rounding function,(to 1 decimal place in my case worked great) , inside the value property.
Hope you gonna check this error and fix it!
Happy coding

stepper in tableViewCell

    let qytStepper = cell.viewWithTag(97) as! GMStepper
    qytStepper.labelFont = UIFont.systemFontOfSize(15.0)
    qytStepper.minimumValue = 0
    qytStepper.layer.borderWidth = 1.0
    qytStepper.layer.borderColor = UIColor.lightGrayColor().CGColor
    qytStepper.tag = indexPath.row
    qytStepper.addTarget(self, action: "stepperValueChanged:", forControlEvents: .ValueChanged)

not working

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.