Is there a way to have iOS' autocorrect ignore a single word or regex in a UITextView?

限于喜欢 提交于 2020-01-21 07:00:47

问题


I'm building a textview to compose status messages, and one of the functions it has is to include #hashtags within the text of a status message.

However, these #hashtags often aren't actual words, so iOS' autocorrect functionality causes them to appear with a red underline once the hashtag has been typed.

(For example: #seafair2014, #wwdc, and other non-word hashtags)

Is there a way to temporarily add a term to the iOS dictionary, so as to ignore any #hashtag or @username typos but still provide spell-checking for the rest of the UITextView?


回答1:


Use +[UITextChecker learnWord:]. You can listen to change events and dynamically add hashtag words.

Apple Reference



来源:https://stackoverflow.com/questions/21996291/is-there-a-way-to-have-ios-autocorrect-ignore-a-single-word-or-regex-in-a-uitex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!