सबसे पहले, मैं सर्जियो का शुक्रिया अदा करना चाहता हूं ... उसका जवाब मुझे शुरू कर दिया लेकिन मैंने सोचा कि मैं कुछ कोड साझा करूंगा जो मुझे स्पष्ट नहीं था कि मुझे इसे काम करने के लिए लिखना था: अंत में इस थंबनेल you'l प्रदर्शित करने के लिए
- (void)webViewDidFinishLoad:(UIWebView *)webView {
UIGraphicsBeginImageContext(webView.bounds.size);
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *webViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *thumbnailData = UIImagePNGRepresentation(webViewImage);
[webView removeFromSuperview];
}
,:
// Your width and height can be whatever you like, but if you want this to render
// off screen, you need an x and y bigger than the superview's width and height
UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(largerScreenDimension, largerScreenDimension, largerScreenDimension, largerScreenDimension)];
[self.view addSubview:webView]; // UIWebViews without an assigned superview don't load ever.
webView.delegate = self; // or whoever you have implement UIWebViewDelegate
webView.scalesToFit = YES; // This zooms the page appropriately to fill the entire thumbnail.
[webView loadRequest:[NSURLRequest requestWithURL:url]];
तो यह आपके प्रतिनिधि में लागू:
यहाँ कैसे कभी होने यह प्रदर्शित बिना एक पेज के लिए एक थंबनेल बनाने के लिए है मुझे कुछ चाहिए:
thumbnailImageView.image = [UIImage imageWithData:thumbnailData];
एक बोनस चीज़ के रूप में मैं उल्लेख करूंगा, मैं एक साथ कई थंबनेल उत्पन्न करना चाहता था। मुझे objc_setAssociatedObject()
और objc_getAssociatedObject()
का उपयोग करके पता चला कि कौन सा वेब व्यू लोड हो रहा था, यह ट्रैक रखने में बहुत मददगार था। इस सवाल के दायरे से परे यह काम करने के तरीके पर विस्तार से जा रहा है।
क्या आप इसे आईओएस में करना चाहते हैं? –