财神随手记账

AlertWith1inputTextFieldView.m 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // AlertWith1inputTextFieldView.m
  3. // FoolsparadiseView
  4. //
  5. // Created by foolsparadise on 19/9/2017.
  6. // Copyright © 2017 github.com/foolsparadise All rights reserved.
  7. //
  8. #import "AlertWith1inputTextFieldView.h"
  9. @interface AlertWith1inputTextFieldView ()<UITextFieldDelegate>
  10. @property (nonatomic, strong) UIButton *alertButton;
  11. @property (nonatomic, strong) UITextField *leftTextField;
  12. @property (nonatomic, strong) UIButton *rightButton;
  13. @end
  14. @implementation AlertWith1inputTextFieldView
  15. /*
  16. // Only override drawRect: if you perform custom drawing.
  17. // An empty implementation adversely affects performance during animation.
  18. - (void)drawRect:(CGRect)rect {
  19. // Drawing code
  20. }
  21. */
  22. - (instancetype)initWithFrame:(CGRect)frame
  23. {
  24. self = [super initWithFrame:frame];
  25. if (self) {
  26. [self setupUI];
  27. }
  28. return self;
  29. }
  30. - (void)setupUI {
  31. self.layer.masksToBounds = YES;
  32. self.layer.cornerRadius = 0;
  33. self.layer.borderWidth = 1;
  34. self.backgroundColor = [UIColor whiteColor];
  35. }
  36. - (void)setTitleAlertString:(NSString *)titleAlertString
  37. {
  38. [self.alertButton setTitle:NSLocalizedStringFromTable(titleAlertString, @"InfoPlist", nil) forState:UIControlStateNormal];
  39. [self.alertButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  40. }
  41. - (void)setleftShowString:(NSString *)leftShowString
  42. {
  43. self.leftTextField.text = NSLocalizedStringFromTable(leftShowString, @"InfoPlist", nil);
  44. }
  45. - (void)setRightButtonString:(NSString *)rightButtonString
  46. {
  47. [self.rightButton setTitle:NSLocalizedStringFromTable(rightButtonString, @"InfoPlist", nil) forState:UIControlStateNormal];
  48. [self.rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  49. }
  50. - (UIButton *)alertButton
  51. {
  52. if (!_alertButton) {
  53. _alertButton = [UIButton buttonWithType:UIButtonTypeCustom];
  54. _alertButton.backgroundColor = [UIColor clearColor];
  55. //[_alertButton setTitle:@"SomeTitle" forState:UIControlStateNormal];
  56. //_alertButton.titleLabel.font = [UIFont systemFontOfSize:14];
  57. //[_alertButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  58. //_alertButton.layer.borderColor = RGBCOLOR(226, 226, 226).CGColor;
  59. //_alertButton.layer.borderWidth = 1;
  60. _alertButton.layer.borderColor = [UIColor whiteColor].CGColor;
  61. _alertButton.layer.borderWidth = 0;
  62. [_alertButton.layer setMasksToBounds:YES];
  63. [_alertButton.layer setCornerRadius:0];
  64. _alertButton.titleLabel.font = [UIFont systemFontOfSize:15];
  65. _alertButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  66. _alertButton.tag = 0; //为零,就不响应了
  67. [_alertButton addTarget:self action:@selector(click_Button:) forControlEvents:UIControlEventTouchUpInside];
  68. }
  69. return _alertButton;
  70. }
  71. - (UITextField *)leftTextField
  72. {
  73. if (!_leftTextField) {
  74. _leftTextField = [UITextField new];
  75. _leftTextField.frame = CGRectMake(5, 5, SCREEN_WIDTH - 30, 35);
  76. _leftTextField.backgroundColor = [UIColor whiteColor];
  77. //_leftTextField.placeholder = @"Please Input Your Nickname";
  78. _leftTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  79. _leftTextField.delegate = self;
  80. _leftTextField.keyboardAppearance = UIKeyboardTypeASCIICapable;
  81. _leftTextField.returnKeyType = UIReturnKeyDone;
  82. _leftTextField.autocorrectionType = UITextAutocorrectionTypeNo;
  83. _leftTextField.borderStyle = UITextBorderStyleNone;
  84. _leftTextField.secureTextEntry = NO;
  85. _leftTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
  86. _leftTextField.font = [UIFont systemFontOfSize:14];;
  87. _leftTextField.layer.borderWidth = 0.5;
  88. _leftTextField.layer.cornerRadius = 12;
  89. NSString *resourePath = [[NSBundle mainBundle] resourcePath];
  90. UIImageView *leftView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[resourePath stringByAppendingPathComponent:@"ico_leftTextField_leftView"]]];
  91. _leftTextField.leftView = leftView;
  92. _leftTextField.leftView.frame = CGRectMake(20, 0, leftView.image.size.width, leftView.image.size.height);
  93. _leftTextField.leftViewMode = UITextFieldViewModeAlways;
  94. //_leftTextField.tag = 0; //为零,就不响应了
  95. //[_leftTextField addTarget:self action:@selector(click_Button:) forControlEvents:UIControlEventTouchUpInside];
  96. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 5)];
  97. _leftTextField.leftView = view;
  98. _leftTextField.leftViewMode = UITextFieldViewModeAlways;
  99. }
  100. return _leftTextField;
  101. }
  102. - (UIButton *)rightButton
  103. {
  104. if (!_rightButton) {
  105. _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
  106. _rightButton.backgroundColor = [UIColor whiteColor];
  107. //[_rightButton setTitle:@"SomeTitle" forState:UIControlStateNormal];
  108. //_rightButton.titleLabel.font = [UIFont systemFontOfSize:14];
  109. //[_rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  110. _rightButton.layer.borderColor = [UIColor whiteColor].CGColor;
  111. _rightButton.layer.borderWidth = 0;
  112. [_rightButton.layer setMasksToBounds:YES];
  113. [_rightButton.layer setCornerRadius:12.0];
  114. _rightButton.titleLabel.font = [UIFont systemFontOfSize:15];
  115. _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
  116. _rightButton.tag = 1; //为零,就不响应了
  117. [_rightButton addTarget:self action:@selector(click_Button:) forControlEvents:UIControlEventTouchUpInside];
  118. }
  119. return _rightButton;
  120. }
  121. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  122. {
  123. [self.leftTextField resignFirstResponder];
  124. }
  125. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  126. {
  127. // NSString *limited_string = @"abcdefghijklmnopqrstuvwxyz"
  128. // @"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  129. // @"0123456789";
  130. // NSRange range11 = [limited_string rangeOfString:string];
  131. // if(range11.location == NSNotFound && range.length !=1)
  132. // return NO;
  133. //
  134. return YES;
  135. }
  136. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  137. {
  138. [self.leftTextField resignFirstResponder];
  139. return YES;
  140. }
  141. - (void)click_Button:(UIButton *)btn
  142. {
  143. NSInteger tagg = (long)btn.tag;
  144. //NSLog(@"click_leftTextField %ld", tagg);
  145. if(tagg>0)
  146. {
  147. [self.delegate AlertWith1inputTextFieldViewDelegate:self.tag withInputString:self.leftTextField.text];
  148. }
  149. }
  150. @end