iPhone Programming: Deactivate spell check in UITextView

后端 未结 4 1203
野趣味
野趣味 2020-12-17 20:48

UITextAutocorrectionTypeNo didn\'t work for me.

I\'m working on a crossword app for the iPhone. The questions are in UITextViews and I use UITextFields for the User-

4条回答
  •  心在旅途
    2020-12-17 21:35

    Important

    Disabling spell check will NOT update the UI of the red-line until the text itself is also updated. Simply setting the spellCheck to NO is not enough.

    To force a UI update, set the spellcheck property to NO, then toggle the text blank then back, like so:

    _textView.spellCheckingType = UITextSpellCheckingTypeNo;
    
    NSString *currentText = _textView.text;
    NSAttributedString *currentAttributedText = _textView.attributedText;
    _textView.text = @"";
    _textView.attributedText = [NSAttributedString new];
    _textView.text = currentText;
    if (currentAttributedText.length > 0) {
        _textView.attributedText = currentAttributedText;
    }
    

提交回复
热议问题