项目作者: imqiuhang

项目描述 :
better textField for iOS
高级语言: Objective-C
项目地址: git://github.com/imqiuhang/QHTextField.git
创建时间: 2019-08-14T12:40:41Z
项目社区:https://github.com/imqiuhang/QHTextField

开源协议:MIT License

下载


QHTextField

License MIT

更加规范和方便的使用textField

Features

  1. /*!********************************************************************************
  2. ╭----------------╮
  3. | UI规范化的输入框 | 普通输入框, 文字内间距规范,定制
  4. ╰----------------╯
  5. ╭-----------------------╮
  6. | ✪ UI规范化的输入框 x | 左右icon规范话使用, 提供一些已有的右视图类型
  7. ╰-----------------------╯
  8. ╭----------------------------╮
  9. | 前置标题 UI规范化的输入框 x | 左标题规范化使用
  10. ╰----------------------------╯
  11. ╭---------------------╮
  12. | 数据校验 999.99 ✪ | 提供正则、字符集和自定义匹配规则的快速过滤
  13. ╰---------------------╯
  14. ********************************************************************************/

demo

Podfile

To integrate QHTextField into your Xcode project using CocoaPods, specify it in your Podfile:

  1. source 'https://github.com/CocoaPods/Specs.git'
  2. platform :ios, '8.0'
  3. target 'TargetName' do
  4. pod 'QHTextField', '~> 0.1.1'
  5. end

Installation with Carthage

To integrate QHTextField into your Xcode project using Carthage, specify it in your Cartfile:

  1. github "QHTextField/QHTextField" ~> 0.1.1

Usage

  1. /*! 以下大部分设置都支持xib @see IBInspectable */
  2. // appearance setting support
  3. [QHTextField appearance].leftViewTextColor = [UIColor purpleColor];
  4. QHTextField *textField = [QHTextField new];
  5. // ------------------- UI相关
  6. // 左icon显示
  7. textField.leftViewIcon = [UIImage imageNamed:@"icon_left_test"];
  8. // 左文字显示
  9. textField.leftViewText = @"标题显示";
  10. // 左自定义富文本显示";
  11. textField.leftViewAttText = [self customerAttributedString];
  12. // 右显示清除按钮
  13. textField.leftViewText = @"标题显示";
  14. textField.rightViewType = QHTextFieldRightViewTypeCleanButton;
  15. [textField setOnRightViewSelect:^(QHTextField * _Nonnull textField) {
  16. // rightViewSelect
  17. }];
  18. // 右自定义图片
  19. textField.leftViewIcon = [UIImage imageNamed:@"icon_left_test"];
  20. textField.rightViewIcon = [UIImage imageNamed:@"icon_left_test"];
  21. // 有左右view设置文字内间距50
  22. textField.leftViewIcon = [UIImage imageNamed:@"icon_left_test"];
  23. textField.rightViewIcon = [UIImage imageNamed:@"icon_left_test"];
  24. textField.textLeftHasViewInset = 50.f;
  25. textField.textRightHasViewInset = 50.f;
  26. // 无左右view设置文字内间距50
  27. textField.textLeftNormalInset = 50.f;
  28. textField.textRightNormalInset = 50.f;
  29. // ------------------- 匹配相关
  30. textField.textRightNormalInset = 50.f;
  31. // 设置匹配类型为 1:Number
  32. textField.textMatchRules.textMatchingType = QHTFTextMatchingTypeNumber;
  33. textField.textAlignment = NSTextAlignmentRight;
  34. // 设置匹配类型为 2:无限制小数
  35. textField.textMatchRules.textMatchingType = QHTextFieldRightViewTypeDecimals;
  36. textField.textAlignment = NSTextAlignmentRight;
  37. // 设置匹配类型为 3:最多2位小数";
  38. textField.textMatchRules.textMatchingType = QHTextFieldRightViewTypeTowFractionDigitsDecimals;
  39. textField.textAlignment = NSTextAlignmentRight;
  40. // 设置自定义正则 ^[0-9]+$ 最大输入11位
  41. textField.textMatchRules.textMatchingRegEx = @"^[0-9]+$";
  42. textField.textMatchRules.inputLimit = 11;
  43. [textField setOnReachInputLimit:^(QHTextField * _Nonnull textField) {
  44. // inputLimit
  45. }];
  46. /// 自定义CharacterSet 小写字母+ABC 和代理
  47. NSMutableCharacterSet *set = [NSMutableCharacterSet lowercaseLetterCharacterSet];
  48. [set formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"ABC"]];
  49. textField.textMatchRules.textMatchingCharacterSet = [set copy];
  50. textField.delegate = self;
  51. // 实现delegate的方法不会影响QHTextField内部的实现
  52. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  53. // 优先会使用外部返回的结果
  54. if([string isEqualToString:@"a"]) {
  55. [self showHUD:@"点了a,可以被输入,但先被外部过滤了"];
  56. return NO;
  57. }
  58. return YES;
  59. }