OC Control PPNumberButton

一直觉得自己写的不是技术,而是情怀,一个个的教程是自己这一路走来的痕迹。靠专业技能的成功是最具可复制性的,希望我的这条路能让你们少走弯路,希望我能帮你们抹去知识的蒙尘,希望我能帮你们理清知识的脉络,希望未来技术之巅上有你们也有我。

使用场景:电商项目加减商品进购物车
OC  Control    PPNumberButton

控件所提供的方法

- (instancetype)initWithFrame:(CGRect)frame;
+ (instancetype)numberButtonWithFrame:(CGRect)frame;

/** 加减按钮的Block回调*/
@property (nonatomic, copy) void(^resultBlock)(PPNumberButton *ppBtn,CGFloat number, BOOL increaseStatus/* 是否为加状态*/);
/** 代理*/
@property (nonatomic, weak) id<PPNumberButtonDelegate> delegate;

#pragma mark - 自定义样式属性设置
/** 是否开启抖动动画, default is NO*/
@property (nonatomic, assign ) IBInspectable BOOL shakeAnimation;
/** 为YES时,初始化时减号按钮隐藏(饿了么/百度外卖/美团外卖按钮模式),default is NO*/
@property (nonatomic, assign ) IBInspectable BOOL decreaseHide;
/** 是否可以使用键盘输入,default is YES*/
@property (nonatomic, assign, getter=isEditing) IBInspectable BOOL editing;

/** 设置边框的颜色,如果没有设置颜色,就没有边框 */
@property (nonatomic, strong ) IBInspectable UIColor *borderColor;

/** 输入框中的内容 */
@property (nonatomic, assign ) CGFloat currentNumber;
/** 递增步长,默认步长为1 */
@property (nonatomic, assign ) CGFloat stepValue;

/** 输入框中的字体大小 */
@property (nonatomic, assign ) IBInspectable CGFloat inputFieldFont;

/** 长按加减的时间间隔,默认0.1s,设置为 CGFLOAT_MAX 则关闭长按加减功能*/
@property (nonatomic, assign ) IBInspectable CGFloat longPressSpaceTime;

/** 加减按钮的字体大小 */
@property (nonatomic, assign ) IBInspectable CGFloat buttonTitleFont;
/** 加按钮背景图片 */
@property (nonatomic, strong ) IBInspectable UIImage *increaseImage;
/** 减按钮背景图片 */
@property (nonatomic, strong ) IBInspectable UIImage *decreaseImage;
/** 加按钮标题 */
@property (nonatomic, copy   ) IBInspectable NSString *increaseTitle;
/** 减按钮标题 */
@property (nonatomic, copy   ) IBInspectable NSString *decreaseTitle;

/** 最小值, default is 0 */
@property (nonatomic, assign ) IBInspectable CGFloat minValue;
/** 最大值 */
@property (nonatomic, assign ) CGFloat maxValue;
/** 目前支持一位小数的递增 */
@property (nonatomic, assign ) BOOL decimalNum;

@end

#pragma mark - NSString分类
@interface NSString (PPNumberButton)
/**
 字符串 nil, @"", @"  ", @"\n" Returns NO;
 其他 Returns YES.
 */
- (BOOL)pp_isNotBlank;

使用

PPNumberButtonDelegate


@property (nonatomic,strong) PPNumberButton *numberBtn;

  self.numberBtn = [PPNumberButton new];
  self.numberBtn.shakeAnimation = YES;
  self.numberBtn.editing = YES;
  self.numberBtn.borderColor = [Color line];
  self.numberBtn.currentNumber = 1;
  self.numberBtn.inputFieldFont = 16;
  self.numberBtn.longPressSpaceTime = 0.5;
  self.numberBtn.buttonTitleFont = 16;
  self.numberBtn.increaseTitle = @"+";
  self.numberBtn.decreaseTitle = @"-";
  self.numberBtn.minValue = 1;
  self.numberBtn.stepValue = 1;
  self.numberBtn.delegate = self;
  self.numberBtn.addTo(self.bgView).makeCons(^{
    make.right.equal.view(self.bgView).constants(-10);
    make.top.equal.view(self.labelView).bottom.constants(5);
    make.height.equal.constants(30);
    make.width.equal.constants(90);
  });
  
#pragma  mark LabelView  用于返回选中数量
- (void)pp_numberButton:(PPNumberButton *)numberButton number:(NSInteger)number increaseStatus:(BOOL)increaseStatus{

}

效果
OC  Control    PPNumberButton

上一篇:009.OpenShift管理及监控


下一篇:【粉丝来信】深度复盘自己的秋招,字节客户端一二三面面经分享(已OC)!