大佬教程收集整理的这篇文章主要介绍了objective-c – CustomKeyBoardExtension中的当前文本选择,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在寻找方法来了解光标在CustomKeyboardExtension中的UITextField,UITextView等等的位置…但我没有看到类似的东西.
我看到SwiftKey应用程序(http://swiftkey.com)可以做到(或做类似的事情).当我更改光标时,建议文本将会改变(见下图).
问:我们如何才能获得当前的文本选择?
…
更新:29/09/2014
好吧,我太傻了.我们可以使用textContextBeforeInput,textDocumentAxyInput方法的textDocumentProxy属性.我以为“之前”,“之后”是关于时间的.实际上这是关于这个位置的.
对不起!我浪费你的时间:(
-(NSString *) lastWordBeforeInput{ NSArray *arrayOfSplitsString = [self.textDocumentProxy.documentContextBeforeInput componentsSeparatedByString:@" "]; int countIndex = arrayOfSplitsString.count - 1; NSCharacterSet *chset = [NSCharacterSet alphanumericCharacterSet]; NSCharacterSet *invertedchset = [chset invertedSet]; while (counTindex > 0) { NSString *lastWordOfSentance = [arrayOfSplitsString objectATindex:counTindex--]; if ([[lastWordOfSentance StringByTrimmingCharactersInSet:invertedchset] rangeOfCharacterFromSet:chset].LOCATIOn != NsnotFound) { return [lastWordOfSentance StringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; } } return @""; }
然后根据需要使用textWillChange / textDidChange调用它.
- (void)textWillChange:(id<UITexTinput>)texTinput { // The app is about to change the document's contents. Perform any preparation here. NSLog(@"%@",[self lastWordBeforeInput]); }
希望这会帮助你.
以上是大佬教程为你收集整理的objective-c – CustomKeyBoardExtension中的当前文本选择全部内容,希望文章能够帮你解决objective-c – CustomKeyBoardExtension中的当前文本选择所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。