GroupCreateView.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // GroupCreateView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/23.
  6. //
  7. #import "GroupCreateView.h"
  8. @interface GroupCreateView ()<UITextFieldDelegate, UITextViewDelegate>
  9. @property (weak, nonatomic) IBOutlet UITextField *groupNameField;
  10. @property (weak, nonatomic) IBOutlet UITextView *inputText;
  11. @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
  12. @property (nonatomic, strong) CreateGroupCallback callback;
  13. @end
  14. @implementation GroupCreateView
  15. - (void)awakeFromNib {
  16. [super awakeFromNib];
  17. self.groupNameField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入群聊名称" attributes:@{NSForegroundColorAttributeName:HexRGB(0xc1c1c1), NSFontAttributeName:[UIFont systemFontOfSize:16.0f]}];
  18. self.inputText.delegate = self;
  19. self.groupNameField.delegate = self;
  20. }
  21. + (instancetype)shareInstance {
  22. GroupCreateView *view = [[[NSBundle mainBundle] loadNibNamed:@"GroupCreateView" owner:nil options:nil] firstObject];
  23. return view;
  24. }
  25. - (void)submitCallback:(CreateGroupCallback)callback {
  26. if (callback) {
  27. self.callback = callback;
  28. }
  29. }
  30. - (IBAction)submitAction:(id)sender {
  31. [self endEditing:YES];
  32. if (self.callback) {
  33. if ([NSString isEmptyString:self.groupNameField.text]) {
  34. [self MBPShow:@"请输入群聊名称"];
  35. return;
  36. }
  37. self.callback(self.groupNameField.text, self.inputText.text);
  38. }
  39. }
  40. #pragma mark ---- delegate
  41. - (void)textViewDidBeginEditing:(UITextView *)textView {
  42. self.tipsLabel.hidden = YES;
  43. }
  44. - (void)textViewDidEndEditing:(UITextView *)textView {
  45. if ([NSString isEmptyString:textView.text]) {
  46. self.tipsLabel.hidden = NO;
  47. }
  48. }
  49. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  50. if ([text isEqualToString:@"\n"]) {
  51. [self endEditing:YES];
  52. return YES;
  53. }
  54. if ([text isEqualToString:@""]) {
  55. return YES;
  56. }
  57. return YES;
  58. }
  59. - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
  60. [self endEditing:YES];
  61. return YES;
  62. }
  63. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  64. [self endEditing:YES];
  65. }
  66. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  67. if ([string isEqualToString:@"\n"]) {
  68. [self endEditing:YES];
  69. return YES;
  70. }
  71. return YES;
  72. }
  73. /*
  74. // Only override drawRect: if you perform custom drawing.
  75. // An empty implementation adversely affects performance during animation.
  76. - (void)drawRect:(CGRect)rect {
  77. // Drawing code
  78. }
  79. */
  80. @end