ChatComplainBodyView.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // ChatComplainBodyView.m
  3. // TeacherDaya
  4. //
  5. // Created by Kyle on 2021/5/12.
  6. // Copyright © 2021 DayaMusic. All rights reserved.
  7. //
  8. #import "ChatComplainBodyView.h"
  9. @interface ChatComplainBodyView ()<UITextFieldDelegate, UITextViewDelegate>
  10. @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
  11. @property (weak, nonatomic) IBOutlet UIImageView *titleIcon;
  12. @property (weak, nonatomic) IBOutlet UIImageView *imageIcon;
  13. @property (weak, nonatomic) IBOutlet UILabel *countLabel;
  14. @end
  15. @implementation ChatComplainBodyView
  16. - (void)awakeFromNib {
  17. [super awakeFromNib];
  18. self.inputText.delegate = self;
  19. NSString *titleIcon = @"complain_title_green";
  20. NSString *imageIcon = @"complain_photo_green";
  21. if ([UserDefault(TENANT_ID) integerValue] > 0) {
  22. titleIcon = @"complain_title_red";
  23. imageIcon = @"complain_photo_red";
  24. }
  25. [self.titleIcon setImage:[UIImage imageNamed:titleIcon]];
  26. [self.imageIcon setImage:[UIImage imageNamed:imageIcon]];
  27. }
  28. + (instancetype)shareInstance {
  29. ChatComplainBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"ChatComplainBodyView" owner:nil options:nil] firstObject];
  30. return view;
  31. }
  32. #pragma mark ---- delegate
  33. - (void)textViewDidBeginEditing:(UITextView *)textView {
  34. self.tipsLabel.hidden = YES;
  35. }
  36. - (void)textViewDidEndEditing:(UITextView *)textView {
  37. if ([NSString isEmptyString:textView.text]) {
  38. self.tipsLabel.hidden = NO;
  39. }
  40. }
  41. - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
  42. [self endEditing:YES];
  43. return YES;
  44. }
  45. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  46. [self endEditing:YES];
  47. }
  48. -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  49. // 输入控制
  50. NSString *newString = [textView.text stringByReplacingCharactersInRange:range withString:text];
  51. if (newString.length > 200) {
  52. return NO;
  53. }
  54. self.countLabel.text = [NSString stringWithFormat:@"%zd/200", newString.length];
  55. return YES;
  56. }
  57. + (CGFloat)getViewHeight {
  58. return 480.0f;
  59. }
  60. /*
  61. // Only override drawRect: if you perform custom drawing.
  62. // An empty implementation adversely affects performance during animation.
  63. - (void)drawRect:(CGRect)rect {
  64. // Drawing code
  65. }
  66. */
  67. @end