3 Star 1 Fork 0

Gitee 极速下载/PPNumberButton

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/jkpang/PPNumberButton.git
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

iOS中一款高度可定制性商品计数按钮,使用简单!

  • 支持自定义加/减按钮的标题内容、背景图片;
  • 支持设置边框颜色;
  • 支持使用键盘输入;
  • 支持长按加/减按钮快速加减;
  • 支持block回调与delegate(代理)回调;
  • 支持使用xib创建、直接在IB面板设置相关属性;
  • 支持设置maxValue(最大值)与minValue(最小值).
  • 支持按钮自定义为京东/淘宝样式,饿了么/美团外卖/百度外卖样式;

新建 PP-iOS学习交流群 : 323408051 有关于PP系列封装的问题和iOS技术可以在此群讨论

简书地址 ;

如果你需要Swift版本,请戳: https://github.com/jkpang/PPNumberButtonSwift

示例图1 示例图2

Requirements 要求

  • iOS 7+
  • Xcode 8+

Installation 安装

1.手动安装:

下载DEMO后,将子文件夹PPNumberButton拖入到项目中, 导入头文件PPNumberButton.h开始使用.

2.CocoaPods安装:

first pod 'PPNumberButton' then pod install或pod install --no-repo-update`

如果发现pod search PPNumberButton 不是最新版本,在终端执行pod setup命令更新本地spec镜像缓存(时间可能有点长),重新搜索就OK了

Usage 使用方法

实例化方法

[[PPNumberButton alloc] init];:默认的frame为CGRectMake(0, 0, 110, 30) 或 [[PPNumberButton alloc] initWithFrame:frame];

[PPNumberButton numberButtonWithFrame:frame];: 类方法创建

1.自定义加减按钮文字标题

PPNumberButton *numberButton = [PPNumberButton numberButtonWithFrame:CGRectMake(100, 100, 110, 30)];
// 开启抖动动画
numberButton.shakeAnimation = YES;
// 设置最小值
numberButton.minValue = 2;
// 设置最大值
numberButton.maxValue = 10;
// 设置输入框中的字体大小
numberButton.inputFieldFont = 23;
numberButton.increaseTitle = @"+";
numberButton.decreaseTitle = @"-";
    
numberButton.resultBlock = ^(NSString *num){
    NSLog(@"%@",num);
};
[self.view addSubview:numberButton];

2.边框状态

PPNumberButton *numberButton = [PPNumberButton numberButtonWithFrame:CGRectMake(100, 160, 150, 30)];
//设置边框颜色
numberButton.borderColor = [UIColor grayColor];
numberButton.increaseTitle = @"+";
numberButton.decreaseTitle = @"-";
numberButton.resultBlock = ^(NSString *num){
    NSLog(@"%@",num);
}; 
[self.view addSubview:numberButton];

3.自定义加减按钮背景图片

PPNumberButton *numberButton = [PPNumberButton numberButtonWithFrame:CGRectMake(100, 220, 100, 30)];
numberButton.shakeAnimation = YES;
numberButton.increaseImage = [UIImage imageNamed:@"increase_taobao"];
numberButton.decreaseImage = [UIImage imageNamed:@"decrease_taobao"];
numberButton.resultBlock = ^(NSString *num){
    NSLog(@"%@",num);
};
[self.view addSubview:numberButton];

4.饿了么,美团外卖,百度外卖样式

PPNumberButton *numberButton = [PPNumberButton numberButtonWithFrame:CGRectMake(100, 280, 100, 30)];
// 初始化时隐藏减按钮
numberButton.decreaseHide = YES;
numberButton.increaseImage = [UIImage imageNamed:@"increase_meituan"];
numberButton.decreaseImage = [UIImage imageNamed:@"decrease_meituan"];
numberButton.resultBlock = ^(NSString *num){
    NSLog(@"%@",num);
};
[self.view addSubview:numberButton];

更多详细用法参见Demo

使用xib创建

在控制器界面拖入UIView控件,在右侧的设置栏中将class名修改为PPNumberButton,按回车就OK了 (注意:如果通过Cocopods导入, 使用XIB/SB创建按钮会显示不全,还可能会报错.但APP可以编译运行,这应该是Cocopods或Xcode的问题). 示例图 注意!如果有的同学将控件拖线到代码中,千万不要忘记在拖线的代码文件中导入 "PPNumberButton.h"头文件,否则会报错.

可以在IB界面设置相关属性 示例图

因为之前的项目中需要,在网上找了好多都不符合要求,干脆自己花了点时间撸了一个,现在分享出来,希望能帮到有需要的人。 如果你觉得不错,希望点个Star鼓励一下!

你的Star是我持续更新的动力!

CocoaPods更新日志

• 2018.02.08(tag:0.8.0): 
  1.新增步长stepValue;
  2.新增支持小数功能属性decimalNum.
  
• 2017.07.05(tag:0.7.0): 
  1.新增 longPressSpaceTime 属性,设置长按加减速度的快慢以及功能关闭;
  2.新增tableView列表Demo;
  3.其他代码小细节优化.
  
• 2016.12.22(tag:0.6.0): 
  1.将代理与Block回调的结果数字的类型 由 NSString -> NSInteger;
  2.代理与Block回调结果增加 increaseStatus(加运算状态);
  3.修复有时代理方法没有被实现导致Crash的Bug;
  4.修复减按钮为隐藏模式时,减运算到最小值没有回调的BUG.
								  
• 2016.12.19(tag:0.5.0):
  新增 editing(是否可以使用键盘输入)属性.
  
• 2016.12.09(tag:0.4.0): 
  1.修复当”减”按钮初始化为隐藏模式时, 对其赋值不了的BUG;
  2.优化代码,修复其他小问题.
  
• 2016.11.03(tag:0.3.0)--重大更新:
  1.增加饿了么/美团外卖/百度外卖样式;
  2.调整自定义属性设置接口.
  
• 2016.11.03(tag:0.2.0): 
  设置maxValue(最大值)与minValue(最小值)属性接口.
  
• 2016.09.14(tag:0.1.2);
  添加使用XIB创建时的实时显示
  
• 2016.09.12(tag:0.1.1): 
  小细节优化.
  
• 2016.09.03(tag:0.1.0):
  Pods初始化.

我的App <-> My APP

  • PPHub:一个简洁漂亮的 GitHub iOS客户端 <-> A simple and beautiful GitHub iOS client
    App_Store

联系方式:

PP-iOS学习交流群群二维码

许可证

PPNumberButton 使用 MIT 许可证,详情见 LICENSE 文件。

MIT License Copyright (c) 2016 jkpang <jkpang@outlook.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

仿京东淘宝购物车商品的加减按钮,可定制程度较高,使用简单 支持自定义加/减按钮的标题内容、背景图片; 支持设置边框颜色; 支持使用键盘输入; 支持长按加/减按钮快速加减; 支持bl 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Objective-C
1
https://gitee.com/mirrors/PPNumberButton.git
git@gitee.com:mirrors/PPNumberButton.git
mirrors
PPNumberButton
PPNumberButton
master

搜索帮助