PKYDropDownStepper 0.0.5

PKYDropDownStepper 0.0.5

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2015年5月

Jimmy Huang 维护。



  • yohei okada 和 jimmy huang

PKYStepper

PKYDropDownStepper 是一个可定制的 UIControl,结合了来自 PKYStepper 的轮播器、标签和下拉菜单。

要求

iOS6+

特性

  • 基于 block 的回调,用于值更改、值增加和值减少时
  • 当值处于最大值/最小值时,切换增加/减少按钮的可见性
  • 与 storyboard 一起工作良好

安装

您可以使用 Cocoapods(推荐)或手动复制文件进行安装。

2. 手动复制文件

  1. 克隆此存储库
  2. 将位于 PKYStepper 目录下的文件添加到您的项目中

对于 Objective-C 项目

在您的其中一个文件中添加 #import 'PKYStepper.h',检查您的目标是否有错误。

对于 Swift 项目

您需要创建一个桥接头,并在其中添加 #import "PKYStepper.h" 以在 Swift 代码中使用库。有关创建桥接头的说明,请参阅 Apple 的文档

使用

示例

通过代码创建 PKYStepper

@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];
}

通过 Storyboard 创建 PKYStepper

UIView 拖到您的 Storyboard 中,并将其类更改为 PKYStepper。对于实际示例,请参考示例项目中 StoryboardViewController.storyboard

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

- (void)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];
}

基本使用

设置回调并调用 setup

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

定制

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;

进一步定制

CountLabel 和按钮作为属性公开,如果需要进一步的控制,请使用这些属性进行定制。