Git Product home page Git Product logo

pkystepper's Introduction

PKYStepper CocoaPods CocoaPods CocoaPods

PKYStepper is a customizable UIControl with stepper and label combined.

Requirements

iOS6+

Features

  • block based callback for when value changed, value incremented, and value decremented
  • toggle visibility of increment/decrement button when the value is at maximun/minimum
  • works well with storyboard

Installation

You can either install using cocoapods(recommended) or copying files manually.

1. Cocoapods(Recommended)

In your Podfile, add a line

pod 'PKYStepper', '0.0.1'

then, run pod install.

2. Copy files manually

  1. Clone this repository
  2. Add files under PKYStepper directory to your project

For objective-c projects

Add #import 'PKYStepper.h' in one of your files, and see if your target builds without error.

For swift projects

You need to create a bridging header and add #import "PKYStepper.h" to the header to use the library in swift code. For instruction on how to create a bridging header, please refer to Apple's documentation.

Usage

Example

Creating PKYStepper by storyboard

Drag UIView to your storyboard and change its class to PKYStepper. For actual example, take a look at StoryboardViewController.storyboard in example project.

@property(nonatomic, weak) IBOutlet PKYStepper *stepper;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.stepper.value = 5.0f;
    self.stepper.stepInterval = 5.0f;
    self.stepper.valueChangedCallback = ^(PKYStepper *stepper, float count) {
        stepper.countLabel.text = [NSString stringWithFormat:@"Count: %@", @(count)];
    };
    [self.stepper setup];
}
@IBOutlet weak var stepper: PKYStepper

override func viewDidLoad() {
  super.viewDidLoad()

  stepper.value = 5.0
  stepper.stepInterval = 5.0
  stepper.valueChangedCallback = { stepper, count in
    stepper.countLabel.text = "Dogs: \(count)"
  }
  stepper.setup()
}

Creating PKYStepper by code

@property(nonatomic, strong) PKYStepper *stepper;

- (void)viewDidLoad {
  [super viewDidLoad];

  float width = 260.0f;
  float x = ([UIScreen mainScreen].bounds.size.width - width) / 2.0;

  self.stepper = [[PKYStepper alloc] initWithFrame:CGRectMake(x, 100, width, 44)];
  self.stepper.valueChangedCallback = ^(PKYStepper *stepper, float count) {
    stepper.countLabel.text = [NSString stringWithFormat:@"Dogs: %@", @(count)];
  };
  [self.stepper setup];
  [self.view addSubview:self.stepper];
}

Basic Usage

Set a callback and call setup.

PKYStepper *stepper = [[PKYStepper alloc] initWithFrame:frame];
stepper.valueChangedCallback = ^(PKYStepper *stepper, float count) {
  stepper.countLabel.text = [NSString stringWithFormat:@"%@", @(count)];
};
[stepper setup];
[self.view addSubview:stepper];
let stepper = PKYStepper(frame: frame)
stepper.valueChangedCallback = { stepper, count in
  stepper.countLabel.text = "\(count)"
}
stepper.setup()
self.view.addSubview(stepper)

Customization

float value; // default: 0.0
float stepInterval; // default: 1.0
float minimum; // default: 0.0
float maximum; // default: 100.0
BOOL hidesDecrementWhenMinimum; // default: NO
BOOL hidesIncrementWhenMaximum; // default: NO
CGFloat buttonWidth; // default: 44.0f

// called when value is incremented
PKYStepperIncrementedCallback incrementCallback;

// called when value is decremented
PKYStepperDecrementedCallback decrementCallback;

// customizing appearance
- (void)setBorderColor:(UIColor *)color;
- (void)setBorderWidth:(CGFloat)width;
- (void)setCornerRadius:(CGFloat)radius;

- (void)setLabelTextColor:(UIColor *)color;
- (void)setLabelFont:(UIFont *)font;

- (void)setButtonTextColor:(UIColor *)color forState:(UIControlState)state;
- (void)setButtonFont:(UIFont *)font;

Further Customization

CountLabel and buttons are exposed as properties, so customize using the properties if you need further control.

pkystepper's People

Contributors

parakeety avatar

Watchers

James Cloos avatar  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.