2011-11-19 44 views

回答

0

你將不得不推出自己的。以下是粗略的(iOS 5及更高版本):

在文本視圖頂部放置一個透明背景的視圖。

查找文本的可見範圍,像這樣:

- (NSRange)visibleRangeOfTextView:(UITextView *)textView { 
    CGRect bounds = textView.bounds; 
    UITextPosition *start = [textView characterRangeAtPoint:bounds.origin].start; 
    UITextPosition *end = [textView characterRangeAtPoint:CGPointMake(CGRectGetMaxX(bounds), CGRectGetMaxY(bounds))].end; 
    return NSMakeRange([textView offsetFromPosition:textView.beginningOfDocument toPosition:start], 
        [textView offsetFromPosition:start toPosition:end]); 
} 

在該範圍內拼寫錯誤的單詞搜索。

使用UITextView firstRectForRange方法查找它們的屏幕座標。

突出顯示任何你想要的方式。

決定何時做,這是作爲一個練習的學生急忙:)

+0

我開始和結束爲零在ios 7,但它的工作正常在ios 8.你可以幫我嗎? –

0

您可以使用下面的代碼來檢查天氣印刷文字的正確拼寫與否,如果錯了,然後突出顯示在您的文件這個詞

第一進口

#import <UIKit/UITextChecker.h> 

-(BOOL)isDictionaryWord:(NSString*)word { 
    UITextChecker *checker = [[UITextChecker alloc] init]; 
    NSLocale *currentLocale = [NSLocale currentLocale]; 
    NSString *currentLanguage = [currentLocale objectForKey:NSLocaleLanguageCode]; 
    NSRange searchRange = NSMakeRange(0, [word length]); 
    NSRange misspelledRange = [checker rangeOfMisspelledWordInString:word range: searchRange 
startingAt:0 wrap:NO language: currentLanguage ]; 
    return misspelledRange.location == NSNotFound; 
    } 
+0

漂亮的代碼,但遺憾的是它並沒有解決我的真正的問題。據我所知,在UITextView&c中無法突出顯示文本,這就是爲什麼我想使用內置拼寫錯誤的單詞熒光筆 - 我只想禁用內置的拼寫檢查建議,轉而使用我自己的系統。 –