标签:editable textfield uibutton oid github isequal edit lan bool
2017.07.17 18:10* 字数 66 阅读 644评论 0喜欢 5
最终效果
要求:
实现
#pragma mark - setters
// 当前值
-(void)setValue:(double)value{
if (value < _minValue) {
value = _minValue;
}
else if (value > _maxValue){
value = _maxValue;
}
_minusBtn.enabled = value > _minValue;
_plusBtn.enabled = value < _maxValue;
_valueTF.text = [NSString stringWithFormat:@"%.0f",value];
_value = value;
_valueChanged ? _valueChanged(_value) : nil;
}
// 最大值
-(void)setMaxValue:(double)maxValue{
if (maxValue < _minValue) {
maxValue = _minValue;
}
_maxValue = maxValue;
}
// 最小值
-(void)setMinValue:(double)minValue{
if (minValue > _maxValue) {
minValue = _maxValue;
}
_minValue = minValue;
}
// 是否可输入值
-(void)setIsValueEditable:(BOOL)isValueEditable{
_isValueEditable = isValueEditable;
_valueTF.enabled = _isValueEditable;
}
2. 事件处理
#pragma mark - action
// 按钮点击
-(void)actionForButtonClicked: (UIButton*)sender{
if ([sender isEqual:_minusBtn]) {
self.value = _value - _stepValue;
}
else if([sender isEqual:_plusBtn]){
self.value = _value + _stepValue;
}
}
// 输入事件
-(void)actionForTextFieldValueChanged: (UITextField*)sender{
if ([sender isEqual:_valueTF]) {
self.value = [sender.text doubleValue];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// 值改变回调
_stepper.valueChanged = ^(double value) {
_label.text = [NSString stringWithFormat:@"%.f",value];
};
}
github
https://github.com/BackWorld/HYStepper
标签:editable textfield uibutton oid github isequal edit lan bool
原文地址:https://www.cnblogs.com/sundaysgarden/p/10338612.html