WGDigitField
概述
WGDigitField 是一个可定制的 iOS 数字输入控件。您可以通过非常简单的方式初始化一个强大的数字输入控件。
示例
要运行示例项目,请克隆仓库,并首先从示例目录运行 pod install
特性
- 每个单独的数字视图的样式均可自定义。
- 突出和取消高亮数字视图的可自定义动画。
- 支持 iOS 12 的自动填充。
安装
WGDigitField 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod 'WGDigitField'
如何使用
// WGDigitField<WGDigitView<UIView *> *> means you have to initialize this WGDigitField with an instance of WGDigitView<UIView *> as digitView
WGDigitField<WGDigitView<UIView *> *> *field = [[WGDigitField<WGDigitView<UIView *> *> alloc] initWithDigitViewInitBlock:^WGDigitView<UIView *> * (NSInteger index){
// initializing a background view (UIView or any subclass of UIView if you want)
UIView *background = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 45)];
background.backgroundColor = [UIColor whiteColor];
background.layer.borderColor = [UIColor grayColor].CGColor;
background.layer.borderWidth = 1.f;
background.layer.cornerRadius = 3.f;
// `WGDigitView<UIView *>` means you have to initialize this WGDigitView with an instance of UIView as backgroundView
return [[WGDigitView<UIView *> alloc] initWithBackgroundView:background digitFont:[UIFont systemFontOfSize:25.f] digitColor:[UIColor blackColor]];
} numberOfDigits:6 leadSpacing:25 tailSpacing:25 weakenBlock:^(WGDigitView<UIView *> * _Nonnull digitView) {
// getting it normal
digitView.backgroundView.layer.borderColor = [UIColor grayColor].CGColor;
digitView.backgroundView.layer.borderWidth = 1.f;
} highlightedBlock:^(WGDigitView<UIView *> * _Nonnull digitView) {
// making some UI changes
digitView.backgroundView.layer.borderColor = [UIColor redColor].CGColor;
digitView.backgroundView.layer.borderWidth = 2.f;
// or implementing animations
CAKeyframeAnimation *animation = ...
} fillCompleteBlock:^(WGDigitField * _Nonnull digitField, NSArray<WGDigitView<UIView *> *> * _Nonnull digitViewArray, NSString * _Nonnull text) {
// dismissing keyboard and starting requests
[digitField resignFirstResponder];
}];
作者
王冠宇,微博:@冠宇住在贝克街
许可证
WGDigitField 在 MIT 许可证下可用。更多信息请参阅 LICENSE 文件。