JXInputVC.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // JXInputVC.m
  3. // shiku_im
  4. //
  5. // Created by flyeagleTang on 15-2-4.
  6. // Copyright (c) 2015年 Reese. All rights reserved.
  7. //
  8. #import "JXInputVC.h"
  9. #define INPUT_WIDTH 220
  10. @implementation JXInputVC
  11. @synthesize inputBtn,inputHint,inputTitle,inputText;
  12. - (id)init
  13. {
  14. self = [super init];
  15. if (self) {
  16. _pSelf = self;
  17. // self.parent.alpha = 0.5;
  18. if(!inputTitle)
  19. self.inputTitle = Localized(@"JX_Reply");
  20. if(!inputHint)
  21. self.inputHint = Localized(@"JXInputVC_InputReply");
  22. if(!inputBtn)
  23. self.inputBtn = Localized(@"JX_Send");
  24. if (!_titleFont) {
  25. self.titleFont = g_factory.font15b;
  26. }
  27. if (!_titleColor) {
  28. self.titleColor = [UIColor blackColor];
  29. }
  30. self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
  31. UIView* iv = [[UIView alloc] initWithFrame:CGRectMake((JX_SCREEN_WIDTH-INPUT_WIDTH)/2, self.view.center.y - 80, INPUT_WIDTH, 110)];
  32. iv.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
  33. iv.layer.cornerRadius = 3;
  34. iv.layer.masksToBounds = YES;
  35. [self.view addSubview:iv];
  36. // [iv release];
  37. JXLabel* p;
  38. p = [self createLabel:iv default:inputTitle];
  39. p.font = self.titleFont;
  40. p.textColor = self.titleColor;
  41. p.numberOfLines = 0;
  42. CGSize size = [inputTitle boundingRectWithSize:CGSizeMake(INPUT_WIDTH - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : p.font} context:nil].size;
  43. if (size.height < 25) {
  44. p.textAlignment = NSTextAlignmentCenter;
  45. }else {
  46. p.textAlignment = NSTextAlignmentLeft;
  47. }
  48. // if (size.height < 50) {
  49. // size.height = 50;
  50. // }
  51. p.frame = CGRectMake(10, 10, INPUT_WIDTH - 20, size.height);
  52. _value = [self createTextField:iv default:inputText hint:inputHint];
  53. _value.frame = CGRectMake(10, CGRectGetMaxY(p.frame) + 10, INPUT_WIDTH-20, 25);
  54. [_value becomeFirstResponder];
  55. UIView* line = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(_value.frame) + 10,JX_SCREEN_WIDTH,LINE_WH)];
  56. line.backgroundColor = THE_LINE_COLOR;
  57. [iv addSubview:line];
  58. // [line release];
  59. line = [[UIView alloc]initWithFrame:CGRectMake(INPUT_WIDTH/2,CGRectGetMaxY(line.frame),LINE_WH,34)];
  60. line.backgroundColor = THE_LINE_COLOR;
  61. [iv addSubview:line];
  62. p = [self createLabel:iv default:Localized(@"JX_Cencal")];
  63. p.frame = CGRectMake(0, line.frame.origin.y, INPUT_WIDTH/2, 34);
  64. p.textColor = [UIColor blueColor];
  65. p.delegate = self;
  66. p.didTouch = @selector(onCancel);
  67. p = [self createLabel:iv default:inputBtn];
  68. p.frame = CGRectMake(INPUT_WIDTH/2, line.frame.origin.y, INPUT_WIDTH/2, 34);
  69. p.textColor = [UIColor blueColor];
  70. p.delegate = self;
  71. p.didTouch = @selector(onEnter);
  72. iv.frame = CGRectMake(iv.frame.origin.x, iv.frame.origin.y, iv.frame.size.width, CGRectGetMaxY(p.frame));
  73. }
  74. return self;
  75. }
  76. -(JXLabel*)createLabel:(UIView*)parent default:(NSString*)s{
  77. JXLabel* p = [[JXLabel alloc] initWithFrame:CGRectMake(0,0,INPUT_WIDTH,40)];
  78. p.userInteractionEnabled = NO;
  79. p.text = s;
  80. p.font = g_factory.font15;
  81. p.textAlignment = NSTextAlignmentCenter;
  82. [parent addSubview:p];
  83. // [p release];
  84. return p;
  85. }
  86. -(UITextField*)createTextField:(UIView*)parent default:(NSString*)s hint:(NSString*)hint{
  87. UITextField* p = [[UITextField alloc] init];
  88. p.delegate = self;
  89. p.autocorrectionType = UITextAutocorrectionTypeNo;
  90. p.autocapitalizationType = UITextAutocapitalizationTypeNone;
  91. p.enablesReturnKeyAutomatically = YES;
  92. p.borderStyle = UITextBorderStyleRoundedRect;
  93. p.returnKeyType = UIReturnKeyDone;
  94. // p.clearButtonMode = UITextFieldViewModeAlways;
  95. p.textAlignment = NSTextAlignmentLeft;
  96. p.userInteractionEnabled = YES;
  97. p.text = s;
  98. p.placeholder = hint;
  99. p.font = g_factory.font14;
  100. p.layer.borderWidth = 0;
  101. p.layer.cornerRadius = 0;
  102. p.layer.masksToBounds = YES;
  103. [parent addSubview:p];
  104. // [p release];
  105. return p;
  106. }
  107. -(void)dealloc{
  108. NSLog(@"JXInputVC.dealloc");
  109. // [super dealloc];
  110. }
  111. -(void)onEnter{
  112. if([_value.text length]<=0){
  113. [g_App showAlert:Localized(@"JXAlert_InputSomething")];
  114. return;
  115. }
  116. self.inputText = _value.text;
  117. if(self.delegate != nil && [self.delegate respondsToSelector:self.didTouch])
  118. [self.delegate performSelectorOnMainThread:self.didTouch withObject:self waitUntilDone:NO];
  119. [self onCancel];
  120. }
  121. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  122. [self.view endEditing:YES];
  123. }
  124. -(void)onCancel{
  125. [self.view endEditing:YES];
  126. [self.view removeFromSuperview];
  127. // [self release];
  128. _pSelf = nil;
  129. }
  130. - (BOOL)textFieldShouldReturn:(UITextField *)textField{
  131. [self onEnter];
  132. return YES;
  133. }
  134. @end