由於以前的項目中須要,在網上找了好多都不符合要求,最後乾脆本身擼了一個,如今分享出來,但願能幫到有須要的人。ios
支持按鈕自定義爲京東/淘寶樣式,餓了麼/美團外賣/百度外賣樣式;git
[[PPNumberButton alloc] init];
:默認的frame爲CGRectMake(0, 0, 110, 30)
或[[PPNumberButton alloc] initWithFrame:frame];
或[PPNumberButton numberButtonWithFrame:frame];
: 類方法建立github
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.numberBlock = ^(NSString *num){
NSLog(@"%@",num);
};
[self.view addSubview:numberButton];複製代碼
PPNumberButton *numberButton = [PPNumberButton numberButtonWithFrame:CGRectMake(100, 160, 150, 30)];
//設置邊框顏色
numberButton.borderColor = [UIColor grayColor];
numberButton.increaseTitle = @"+";
numberButton.decreaseTitle = @"-";
numberButton.numberBlock = ^(NSString *num){
NSLog(@"%@",num);
};
[self.view addSubview:numberButton];複製代碼
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.numberBlock = ^(NSString *num){
NSLog(@"%@",num);
};
[self.view addSubview:numberButton];複製代碼
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.numberBlock = ^(NSString *num){
NSLog(@"%@",num);
};
[self.view addSubview:numberButton];複製代碼
在控制器界面拖入UIView控件,在右側的設置欄中將class名修改成PPNumberButton,按回車就OK了.
objective-c
能夠在IB界面設置相關屬性swift
由於以前的項目中須要,在網上找了好多都不符合要求,乾脆本身花了點時間擼了一個,如今分享出來,但願能幫到有須要的人。若是你以爲不錯,但願點個Star鼓勵一下api