How to use autocorrection and shortcut list in iOS8 custom keyboard?

后端 未结 9 976
慢半拍i
慢半拍i 2020-12-07 17:22

I want to use the autocorrection and shortcut list like default English keyboard with my custom keyboard. I check the in keyboard document but don\'t know how to use it.

9条回答
  •  感动是毒
    2020-12-07 17:35

    With regards to auto-correction, I was able to add it using link. Here's the code snippet I used from the link:

    UITextChecker *checker = [[UITextChecker alloc] init];
    
      NSRange checkRange = NSMakeRange(0, self.txView.text.length);
    
      NSRange misspelledRange = [checker rangeOfMisspelledWordInString:self.txView.text 
                                                                 range:checkRange
                                                            startingAt:checkRange.location
                                                                  wrap:NO 
                                                              language:@"en_US"];
    
      NSArray *arrGuessed = [checker guessesForWordRange:misspelledRange inString:self.txView.text language:@"en_US"];
    
      self.txView.text = [self.txView.text stringByReplacingCharactersInRange:misspelledRange 
                                                                   withString:[arrGuessed objectAtIndex:0]];
    

    The full documentation from Apple can be found here.

提交回复
热议问题