ios-WebView实现网页图片获取放大.zip

时间:2022-07-31 13:47:42
【文件属性】:

文件名称:ios-WebView实现网页图片获取放大.zip

文件大小:738KB

文件格式:ZIP

更新时间:2022-07-31 13:47:42

网页视图

获取某个标签的结点个数- (int)nodeCountOfTag:(NSString *)tag { NSString *jsString = [NSString stringWithFormat:@"document.getElementsByTagName('%@').length", tag]; int len = [[self stringByEvaluatingJavaScriptFromString:jsString] intValue]; return len; } 获取所有图片链接 - (NSMutableArray *)getImgs { NSMutableArray *arrImgURL = [[NSMutableArray alloc] init]; int node = [self nodeCountOfTag:@"img"]; for (int i = 0; i < node; i ) { NSString *jsString = [NSString stringWithFormat:@"document.getElementsByTagName('img')[%d].src", i]; NSString *img = [self stringByEvaluatingJavaScriptFromString:jsString]; [arrImgURL addObject:img]; } return arrImgURL; } //使用 - (void)webViewDidFinishLoad:(UIWebView *)webView { [ webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];//静止用户选择 [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout=‘none‘;"];//静止长按 [ webView addClickEventOnImg];//有的图片没有点击事件 _imageArray= [webView getImgs];//获取所有图片链接 NSMutableArray *array=[[ NSMutableArray alloc] init]; for (NSString *string in _imageArray) //剔除没有规则的图集 { if ([string hasPrefix:@"http://upload-images.jianshu.io/upload_images/1"]) { [array addObject:string]; } } _imageArray=array; }


网友评论