How to toggle autocorrectionType on and off for an existing UITextView

前端 未结 4 846
一个人的身影
一个人的身影 2020-12-30 02:42

I have a UITextView in my iPhone app for which I want to be able to toggle the autocorrectionType.

When a user is editing the text view, I want the autocorrectionTy

4条回答
  •  天涯浪人
    2020-12-30 03:11

    In addition to changing the autocorrection type to UITextAutoCorrectionNo, the UITextView must be forced to reevaluate its correction state. setNeedsRedraw is insufficient but setting the text to itself, e.g.

    textView.autocorrectionType = UITextAutocorrectionTypeNo;
    textView.text = textView.text;
    

    makes the red dashed lines go away. NOTE: this workaround relies on undocumented behavior and is not guaranteed to work on future iOS releases.

提交回复
热议问题