我有一个UITextView,并使用其tokenizer来检查用户点击的单词。
我的目标是改变tokenizer所认为的单词。目前似乎将单词定义为连续的字母数字字符,我希望将单词定义为不是空格字符的连续字符("")。
例如:&#39; foo-bar&#39;,&#39; foo / bar&#39;和&#39; foo @@ bar&#39;目前所有这些都将被视为两个单独的单词(&#39; foo&#39;和&#39; bar&#39;)但我希望将它们全部视为单个单词(因为它们都不包含空格)。< / p>
文档讨论了UITextInputStringTokenizer类的子类,但是我找不到某个人这样做的例子,我无法弄清楚如何实现所需的方法:
func isPosition(position: UITextPosition, atBoundary granularity: UITextGranularity, inDirection direction: UITextDirection) -> Bool
func isPosition(position: UITextPosition, withinTextUnit granularity: UITextGranularity, inDirection direction: UITextDirection) -> Bool
func positionFromPosition(position: UITextPosition, toBoundary granularity: UITextGranularity, inDirection direction: UITextDirection) -> UITextPosition?
func rangeEnclosingPosition(position: UITextPosition, withGranularity granularity: UITextGranularity, inDirection direction: UITextDirection) -> UITextRange?