UIWebView+JXSearchWebView.m 1007 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // UIWebView+JXSearchWebView.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 2019/3/13.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "UIWebView+JXSearchWebView.h"
  9. @implementation UIWebView (JXSearchWebView)
  10. - (NSInteger)highlightAllOccurencesOfString:(NSString*)str index:(NSInteger)index
  11. {
  12. NSString *path = [[NSBundle mainBundle] pathForResource:@"SearchWebView" ofType:@"js"];
  13. NSString *jsCode = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
  14. [self stringByEvaluatingJavaScriptFromString:jsCode];
  15. NSString *startSearch = [NSString stringWithFormat:@"MyApp_HighlightAllOccurencesOfString('%@', '%d')",str,index];
  16. [self stringByEvaluatingJavaScriptFromString:startSearch];
  17. NSString *result = [self stringByEvaluatingJavaScriptFromString:@"MyApp_SearchResultCount"];
  18. return [result integerValue];
  19. }
  20. - (void)removeAllHighlights
  21. {
  22. [self stringByEvaluatingJavaScriptFromString:@"MyApp_RemoveAllHighlights()"];
  23. }
  24. @end