Reputation: 1635
In my UITextView when a user spells something incorrectly, it gets underlined in red. How can I remove this without disabling autocorrect?
Upvotes: 1
Views: 1974
Reputation: 989
You can call this function where ever you wanted to check the spelling THen use bellow code
func wordIsSpelledCorrect(_ word: String) -> Bool {
let checker = UITextChecker()
let range = NSMakeRange(0, word.characters.count)
let wordRange = checker.rangeOfMisspelledWord(in: word, range: range, startingAt: 0, wrap: false, language: "en")
return wordRange.location == NSNotFound
}
Use in this way
if wordIsSpelledCorrect((yourTextField.text)!){
}
Upvotes: -1
Reputation: 2400
Text views have properties for both autocorrection and spelling checking. These can be set in the Attributes inspector. Or in code via spellCheckingType
and autocorrectionType
. In your case you would want to disable spell checking whilst leaving autocorrect enabled.
The various possible constant values are detailed at: UITextInputTraits
Upvotes: 3