textview点击弹出键盘的回车键,添加相应事件

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {

    //获取输入内容
    NSString *textStr = [textView.text stringByReplacingCharactersInRange:range withString:text];
    if (![textStr isEqualToString:@""]) {
        self.addBtn.enabled = YES;
        self.addBtn.backgroundColor = RGB(246, 28, 87);
    } else {
        self.addBtn.enabled = NO;
        self.addBtn.backgroundColor = RGB(199, 199, 199);
    }
    
    //点击回车键隐藏键盘
    if([text isEqualToString:@"\n"]) {
        
        [textV resignFirstResponder];
        return NO;
        
    }
    return YES;
}

你可能感兴趣的:(textview点击弹出键盘的回车键,添加相应事件)