UserAuthBodyView.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // UserAuthBodyView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/5/27.
  6. //
  7. #import "UserAuthBodyView.h"
  8. @interface UserAuthBodyView ()<UITextFieldDelegate>
  9. @property (nonatomic, copy) AuthSureCallback callback;
  10. @end
  11. @implementation UserAuthBodyView
  12. - (void)awakeFromNib {
  13. [super awakeFromNib];
  14. self.nameField.delegate = self;
  15. self.cardField.delegate = self;
  16. }
  17. + (instancetype)shareInstance {
  18. UserAuthBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"UserAuthBodyView" owner:nil options:nil] firstObject];
  19. return view;
  20. }
  21. - (void)sureAuthCall:(AuthSureCallback)callback {
  22. if (callback) {
  23. self.callback = callback;
  24. }
  25. }
  26. - (IBAction)sureAction:(id)sender {
  27. if (self.callback) {
  28. self.callback();
  29. }
  30. }
  31. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  32. [string replaceAll:@" " WithString:@""];
  33. if ([string isEqualToString:@"\n"]) {
  34. [self endEditing:YES];
  35. return YES;
  36. }
  37. // 输入控制
  38. NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  39. if (textField == self.cardField) {
  40. if (newString.length > 18) {
  41. return NO;
  42. }
  43. }
  44. return YES;
  45. }
  46. /*
  47. // Only override drawRect: if you perform custom drawing.
  48. // An empty implementation adversely affects performance during animation.
  49. - (void)drawRect:(CGRect)rect {
  50. // Drawing code
  51. }
  52. */
  53. @end