123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- //
- // GroupCreateView.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/23.
- //
- #import "GroupCreateView.h"
- @interface GroupCreateView ()<UITextFieldDelegate, UITextViewDelegate>
- @property (weak, nonatomic) IBOutlet UITextField *groupNameField;
- @property (weak, nonatomic) IBOutlet UITextView *inputText;
- @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
- @property (nonatomic, strong) CreateGroupCallback callback;
- @end
- @implementation GroupCreateView
- - (void)awakeFromNib {
- [super awakeFromNib];
- self.groupNameField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入群聊名称" attributes:@{NSForegroundColorAttributeName:HexRGB(0xc1c1c1), NSFontAttributeName:[UIFont systemFontOfSize:16.0f]}];
- self.inputText.delegate = self;
- self.groupNameField.delegate = self;
- }
- + (instancetype)shareInstance {
- GroupCreateView *view = [[[NSBundle mainBundle] loadNibNamed:@"GroupCreateView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)submitCallback:(CreateGroupCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- - (IBAction)submitAction:(id)sender {
- [self endEditing:YES];
- if (self.callback) {
- if ([NSString isEmptyString:self.groupNameField.text]) {
- [self MBPShow:@"请输入群聊名称"];
- return;
- }
- self.callback(self.groupNameField.text, self.inputText.text);
- }
- }
- #pragma mark ---- delegate
- - (void)textViewDidBeginEditing:(UITextView *)textView {
- self.tipsLabel.hidden = YES;
- }
- - (void)textViewDidEndEditing:(UITextView *)textView {
- if ([NSString isEmptyString:textView.text]) {
- self.tipsLabel.hidden = NO;
- }
- }
- - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
- if ([text isEqualToString:@"\n"]) {
- [self endEditing:YES];
- return YES;
- }
- if ([text isEqualToString:@""]) {
- return YES;
- }
- return YES;
- }
- - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
- [self endEditing:YES];
- return YES;
- }
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
- [self endEditing:YES];
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
- if ([string isEqualToString:@"\n"]) {
- [self endEditing:YES];
- return YES;
- }
- return YES;
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|