JXInputValueVC.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // JXInputValueVC.m
  3. // shiku_im
  4. //
  5. // Created by flyeagleTang on 14-6-10.
  6. // Copyright (c) 2014年 Reese. All rights reserved.
  7. //
  8. #import "JXInputValueVC.h"
  9. //#import "selectTreeVC.h"
  10. #import "selectProvinceVC.h"
  11. #import "selectValueVC.h"
  12. #import "ImageResize.h"
  13. #import "searchData.h"
  14. #define HEIGHT 54
  15. #define STARTTIME_TAG 1
  16. #define IMGSIZE 100
  17. @interface JXInputValueVC ()<UITextViewDelegate>
  18. @property (nonatomic, strong) UIView *baseView;
  19. @property(nonatomic, assign) BOOL isShow;
  20. @end
  21. @implementation JXInputValueVC
  22. @synthesize delegate,didSelect,value;
  23. - (id)init
  24. {
  25. self = [super init];
  26. if (self) {
  27. self.isGotoBack = YES;
  28. // self.title = @"搜索";
  29. self.heightFooter = 0;
  30. self.heightHeader = JX_SCREEN_TOP;
  31. //self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  32. [self createHeadAndFoot];
  33. self.tableBody.backgroundColor = HEXCOLOR(0xF2F2F2);
  34. self.baseView = [[UIView alloc] init];
  35. self.baseView.backgroundColor = [UIColor whiteColor];
  36. [self.tableBody addSubview:self.baseView];
  37. _name = [self createTextField:self.baseView default:self.value hint:Localized(@"JXAlert_InputSomething")];
  38. _name.font = SYSFONT(16);
  39. CGSize constraintSize = CGSizeMake(JX_SCREEN_WIDTH - 20, MAXFLOAT);
  40. CGSize size = [_name sizeThatFits:constraintSize];
  41. _name.frame = CGRectMake(10, 10, JX_SCREEN_WIDTH-20, size.height);
  42. _name.delegate = self;
  43. [_name resignFirstResponder];
  44. self.baseView.frame = CGRectMake(0, 15, JX_SCREEN_WIDTH, size.height+20);
  45. JXLabel* p;
  46. // p = [self createLabel:self.tableHeader default:@"取消" selector:@selector(actionQuit)];
  47. // p.textColor = [UIColor whiteColor];
  48. // p.frame = CGRectMake(10, 20+10, 60, 25d);
  49. p = [self createLabel:self.tableHeader default:Localized(@"JX_Save") selector:@selector(onSave)];
  50. p.textColor = [UIColor whiteColor];
  51. p.backgroundColor = THEMECOLOR;
  52. p.layer.masksToBounds = YES;
  53. p.layer.cornerRadius = 3.f;
  54. p.font = SYSFONT(15);
  55. p.textAlignment = NSTextAlignmentCenter;
  56. p.frame = CGRectMake(JX_SCREEN_WIDTH - 51 - 15, JX_SCREEN_TOP - 8 - 29, 51, 29);
  57. }
  58. return self;
  59. }
  60. -(void)dealloc{
  61. // NSLog(@"JXInputValueVC.dealloc");
  62. // [super dealloc];
  63. }
  64. - (void)viewDidLoad
  65. {
  66. [super viewDidLoad];
  67. if (self.isRoomNum) {
  68. _name.keyboardType = UIKeyboardTypeNumberPad;
  69. }
  70. // Do any additional setup after loading the view.
  71. }
  72. - (void)didReceiveMemoryWarning
  73. {
  74. [super didReceiveMemoryWarning];
  75. // Dispose of any resources that can be recreated.
  76. }
  77. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
  78. return YES;
  79. }
  80. //-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  81. // if (self.isLimit) {
  82. // if (self.limitLen <= 0) {
  83. // self.limitLen = 15;
  84. // }
  85. // if(textField.text.length > self.limitLen && ![string isEqualToString:@""]){
  86. // if (!self.isShow) {
  87. // self.isShow = YES;
  88. // [g_App showAlert:Localized(@"JX_InputLimit")];
  89. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  90. // self.isShow = NO;
  91. // });
  92. // }
  93. // return NO;
  94. // }
  95. // }
  96. //
  97. // return YES;
  98. //}
  99. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  100. if ([text isEqualToString:@"\n"]) {
  101. [self.view endEditing:YES];
  102. [self onSave];
  103. return NO;
  104. }
  105. if (self.isLimit) {
  106. if (self.limitLen <= 0) {
  107. self.limitLen = 15;
  108. }
  109. if(textView.text.length > self.limitLen && ![text isEqualToString:@""]){
  110. if (!self.isShow) {
  111. self.isShow = YES;
  112. [g_server showMsg:Localized(@"JX_InputLimit")];
  113. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  114. self.isShow = NO;
  115. });
  116. }
  117. return NO;
  118. }
  119. }
  120. return YES;
  121. }
  122. - (void)textViewDidChange:(UITextView *)textView {
  123. CGRect frame = textView.frame;
  124. CGSize constraintSize = CGSizeMake(frame.size.width - 20, MAXFLOAT);
  125. CGSize size = [textView sizeThatFits:constraintSize];
  126. textView.frame = CGRectMake(textView.frame.origin.x, textView.frame.origin.y, textView.frame.size.width, size.height);
  127. self.baseView.frame = CGRectMake(self.baseView.frame.origin.x, self.baseView.frame.origin.y, self.baseView.frame.size.width, size.height+20);
  128. }
  129. -(UITextView*)createTextField:(UIView*)parent default:(NSString*)s hint:(NSString*)hint{
  130. UITextView* p = [[UITextView alloc] initWithFrame:CGRectMake(0,INSETS,JX_SCREEN_WIDTH,HEIGHT)];
  131. p.delegate = self;
  132. p.autocorrectionType = UITextAutocorrectionTypeNo;
  133. p.autocapitalizationType = UITextAutocapitalizationTypeNone;
  134. p.enablesReturnKeyAutomatically = YES;
  135. p.scrollEnabled = NO;
  136. // p.borderStyle = UITextBorderStyleNone;
  137. p.returnKeyType = UIReturnKeyDone;
  138. p.showsVerticalScrollIndicator = NO;
  139. p.showsHorizontalScrollIndicator = NO;
  140. // p.clearButtonMode = UITextFieldViewModeAlways;
  141. p.textAlignment = NSTextAlignmentLeft;
  142. p.userInteractionEnabled = YES;
  143. p.backgroundColor = [UIColor whiteColor];
  144. p.text = s;
  145. // p.placeholder = hint;
  146. // p.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, HEIGHT-INSETS*2)];
  147. // p.leftViewMode = UITextFieldViewModeAlways;
  148. p.font = g_factory.font16;
  149. [parent addSubview:p];
  150. // [p release];
  151. return p;
  152. }
  153. -(JXLabel*)createLabel:(UIView*)parent default:(NSString*)s selector:(SEL)selector{
  154. JXLabel* p = [[JXLabel alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH/2,INSETS,JX_SCREEN_WIDTH/2 -20,HEIGHT-INSETS*2)];
  155. p.userInteractionEnabled = NO;
  156. p.text = s;
  157. p.font = g_factory.font14;
  158. p.textAlignment = NSTextAlignmentLeft;
  159. p.didTouch = selector;
  160. p.delegate = self;
  161. [parent addSubview:p];
  162. // [p release];
  163. return p;
  164. }
  165. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  166. {
  167. [self.view endEditing:YES];
  168. return YES;
  169. }
  170. -(void)onSave{
  171. if([_name.text isEqualToString:@""]){
  172. // if (self.isRoomNum) {
  173. // [g_App showAlert:Localized(@"JX_MaximumPeopleNotNull")];
  174. // }else {
  175. // [g_App showAlert:Localized(@"JX_NameCanNot")];
  176. // }
  177. [g_server showMsg:@"内容不能为空"];
  178. return;
  179. }
  180. self.value = _name.text;
  181. if (delegate && [delegate respondsToSelector:didSelect]) {
  182. // [delegate performSelector:didSelect withObject:self];
  183. [delegate performSelectorOnMainThread:didSelect withObject:self waitUntilDone:NO];
  184. }
  185. [self actionQuit];
  186. }
  187. @end