PKYDropDownStepper 是一个可定制的 UIControl,结合了来自 PKYStepper 的轮播器、标签和下拉菜单。
iOS6+
您可以使用 Cocoapods(推荐)或手动复制文件进行安装。
在您的其中一个文件中添加 #import 'PKYStepper.h'
,检查您的目标是否有错误。
您需要创建一个桥接头,并在其中添加 #import "PKYStepper.h"
以在 Swift 代码中使用库。有关创建桥接头的说明,请参阅 Apple 的文档。
@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];
}
将 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 和按钮作为属性公开,如果需要进一步的控制,请使用这些属性进行定制。