UnbindBodyView.m 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // UnbindBodyView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/27.
  6. //
  7. #import "UnbindBodyView.h"
  8. @interface UnbindBodyView ()<UITextFieldDelegate>
  9. @property (nonatomic, copy) UnbindSureCallback callback;
  10. @end
  11. @implementation UnbindBodyView
  12. - (void)awakeFromNib {
  13. [super awakeFromNib];
  14. self.nameField.delegate = self;
  15. self.cardField.delegate = self;
  16. }
  17. + (instancetype)shareInstance {
  18. UnbindBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"UnbindBodyView" owner:nil options:nil] firstObject];
  19. return view;
  20. }
  21. - (void)unbindCallback:(UnbindSureCallback)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. #pragma mark ---- text field delegate
  32. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  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