UITextView

2018-03-20  本文已影响7人  BlessNeo

1. UITextView 点击键盘完成或 Done 按钮收起键盘

Objc

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

    if([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }

    return YES;
}

Swift-4.0

func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
    if text == "\n" {
        textView.resignFirstResponder()
        return false
    }
    return true
}

How to dismiss keyboard for UITextView with return key?

上一篇下一篇

猜你喜欢

热点阅读