酷店

KDPScreenBtnView.m 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // KDPScreenBtnView.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/8.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPScreenBtnView.h"
  9. @interface KDPScreenBtnView ()<UITextFieldDelegate>
  10. @property (nonatomic, strong) UITextField *textField;
  11. @end
  12. @implementation KDPScreenBtnView
  13. - (instancetype)initWithFrame:(CGRect)frame{
  14. if (self = [super initWithFrame:frame]) {
  15. [self setSubViews];
  16. }
  17. return self;
  18. }
  19. - (void)setSubViews{
  20. self.backgroundColor = [UIColor colorWithRGB:0xf4f4f4];
  21. self.textField = [[UITextField alloc] init];
  22. self.textField.delegate = self;
  23. self.textField.keyboardType = UIKeyboardTypeNumberPad;
  24. self.textField.textAlignment = NSTextAlignmentCenter;
  25. self.textField.font = FONT_SYS(14);
  26. [self.textField addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
  27. [self addSubview:self.textField];
  28. [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.size.equalTo(CGSizeMake(self.width, 30));
  30. make.centerX.equalTo(self);
  31. make.centerY.equalTo(self);
  32. }];
  33. }
  34. - (void)setTextColor:(UIColor *)textColor{
  35. _textColor = textColor;
  36. self.textField.textColor = textColor;
  37. }
  38. - (void)setIsEditing:(BOOL)isEditing{
  39. _isEditing = isEditing;
  40. self.textField.enabled = isEditing;
  41. }
  42. - (void)setPlaceHolderText:(NSString *)placeHolderText{
  43. _placeHolderText = placeHolderText;
  44. self.textField.placeholder = placeHolderText;
  45. }
  46. - (void)setText:(NSString *)text{
  47. self.textField.text = text;
  48. }
  49. - (NSString *)text{
  50. if (!self.textField.text.length) {
  51. return @"";
  52. }
  53. return self.textField.text;
  54. }
  55. - (void)textFieldChanged:(UITextField *)textfield{
  56. if ([self.delegate respondsToSelector:@selector(textFieldValueChanged:)]) {
  57. [self.delegate textFieldValueChanged:textfield];
  58. }
  59. }
  60. - (void)textFieldDidEndEditing:(UITextField *)textField{
  61. if ([self.delegate respondsToSelector:@selector(textFieldDidEndEditing:)]) {
  62. [self.delegate textFieldDidEndEditing:textField];
  63. }
  64. }
  65. - (void)textFieldDidBeginEditing:(UITextField *)textField{
  66. if ([self.delegate respondsToSelector:@selector(textFieldDidBeginEditing:)]) {
  67. [self.delegate textFieldDidBeginEditing:textField];
  68. }
  69. }
  70. @end