UITextChecker提示拼写错误

NSString *str = @"hipstar";
UITextChecker *textChecker = [[UITextChecker alloc] init];
NSRange misspelledRange = [textChecker rangeOfMisspelledWordInString:str range:NSMakeRange(0, [str length]) startingAt:0 wrap:NO language:@"en_US"];
NSArray *guesses = [NSArray array];
if (misspelledRange.location != NSNotFound) {
guesses = [textChecker guessesForWordRange:misspelledRange inString:str language:@"en_US"];
NSLog(@"First guess: %@", [guesses firstObject]);
// First guess: hipster
} else {
NSLog(@"Not found");
}

// 学习一个新的单词
[UITextChecker learnWord:str];

展开阅读全文

没有更多推荐了,返回首页