UASInputTextView.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //
  2. // UASInputView.m
  3. // shiku_im
  4. //
  5. // Created by liyangyang-pc on 2018/7/9.
  6. //
  7. #import "UASInputTextView.h"
  8. #import "BRPlaceholderTextView.h"
  9. @interface UASInputTextView ()<UITextViewDelegate>
  10. {
  11. UIView *bgview;
  12. UILabel *nameLabel;
  13. BRPlaceholderTextView *view;
  14. }
  15. @end
  16. @implementation UASInputTextView
  17. - (instancetype)initWithFrame:(CGRect)frame
  18. {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self setView];
  22. }
  23. return self;
  24. }
  25. - (void)setView{
  26. self.backgroundColor = Color(0, 0, 0, 0.5);
  27. bgview =[[UIView alloc] initWithFrame:CGRectMake(30, 200, SCREEN_WIDTH -60, 161) ];
  28. bgview.backgroundColor = BGKJ_COLOR;
  29. [self addSubview:bgview];
  30. nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, bgview.frame.size.width, 20)];
  31. nameLabel.font = FONT_SIZE(18);
  32. nameLabel.textAlignment = NSTextAlignmentCenter;
  33. nameLabel.font = FONT_SIZE(16);
  34. nameLabel.text = @"备注";
  35. [bgview addSubview:nameLabel];
  36. view=[[BRPlaceholderTextView alloc]initWithFrame:CGRectMake(25,35,bgview.frame.size.width-50,75)];
  37. view.placeholder=@"请输入";
  38. view.font=FONT_SIZE(16);
  39. view.backgroundColor = BGKJ_COLOR;
  40. view.layer.borderColor=[UIColor lightGrayColor].CGColor;
  41. view.returnKeyType = UIReturnKeyDone;
  42. view.delegate = self;
  43. [view addMaxTextLengthWithMaxLength:1000 andEvent:^(BRPlaceholderTextView *text) {
  44. }];
  45. [view addTextViewBeginEvent:^(BRPlaceholderTextView *text) {
  46. }];
  47. [view addTextViewEndEvent:^(BRPlaceholderTextView *text) {
  48. }];
  49. [bgview addSubview:view];
  50. UIButton * _SkipThisStepbtn = [UIButton buttonWithType:UIButtonTypeCustom];
  51. _SkipThisStepbtn.frame = CGRectMake((bgview.frame.size.width/3-61)*2+94, 116, 94, 35);
  52. [_SkipThisStepbtn setTitle:Localized(@"UU_custom_sure") forState:UIControlStateNormal];
  53. [_SkipThisStepbtn setTitleColor:Color(51, 162, 238, 1.0) forState:UIControlStateNormal];
  54. [_SkipThisStepbtn setBackgroundColor:BGKJ_COLOR forState:UIControlStateNormal];
  55. [_SkipThisStepbtn setBackgroundColor:Color(51, 162, 238, 1.0) forState:UIControlStateHighlighted];
  56. [_SkipThisStepbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
  57. [_SkipThisStepbtn addTarget:self action:@selector(butAction) forControlEvents:UIControlEventTouchUpInside];
  58. _SkipThisStepbtn.layer.cornerRadius = 5.0f;
  59. _SkipThisStepbtn.layer.borderColor = Color(51, 162, 238, 1.0).CGColor;
  60. _SkipThisStepbtn.layer.borderWidth = 0.8f;
  61. _SkipThisStepbtn.layer.masksToBounds= YES;
  62. [bgview addSubview:_SkipThisStepbtn];
  63. UIButton *SkipThisStepbtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
  64. SkipThisStepbtn1.frame =CGRectMake(bgview.frame.size.width/3 -61 ,116, 94, 35);
  65. [SkipThisStepbtn1 addTarget:self action:@selector(butAction1) forControlEvents:UIControlEventTouchUpInside];
  66. [SkipThisStepbtn1 setTitle:Localized(@"UU_custom_cancle") forState:UIControlStateNormal];
  67. [SkipThisStepbtn1 setTitleColor:Color(51, 162, 238, 1.0) forState:UIControlStateNormal];
  68. [SkipThisStepbtn1 setBackgroundColor:BGKJ_COLOR forState:UIControlStateNormal];
  69. [SkipThisStepbtn1 setBackgroundColor:Color(51, 162, 238, 1.0) forState:UIControlStateHighlighted];
  70. [SkipThisStepbtn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
  71. [bgview addSubview:SkipThisStepbtn1];
  72. SkipThisStepbtn1.layer.cornerRadius = 5.0f;
  73. SkipThisStepbtn1.layer.borderColor = Color(51, 162, 238, 1.0).CGColor;
  74. SkipThisStepbtn1.layer.borderWidth = 0.8f;
  75. SkipThisStepbtn1.layer.masksToBounds = YES;
  76. bgview.layer.cornerRadius = 5.0;
  77. bgview.layer.masksToBounds = YES;
  78. }
  79. -(void)butAction1
  80. {
  81. self.blcok(@"");
  82. [self removeFromSuperview];
  83. }
  84. - (void)butAction{
  85. if (view.text != 0) {
  86. self.blcok(view.text);
  87. }
  88. [self removeFromSuperview];
  89. }
  90. -(void)setTypeStr:(NSString *)typeStr
  91. {
  92. _typeStr = typeStr;
  93. view.text = typeStr;
  94. }
  95. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
  96. if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车,即按下return
  97. //在这里做你响应return键的代码
  98. [view resignFirstResponder];
  99. return NO; //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行
  100. }
  101. return YES;
  102. }
  103. @end