我是iOS的新手。在我的项目中,我需要在图像视图中添加网页的缩略图。我为此创建了一个NSObject类。我在该类中启动了Web视图,但它不会调用UIWebView Delegates.I在此处发布了代码。如果任何人有解决方案或库文件进行缩略图处理可能有用。谢谢。
@interface ThumbNail()<UIWebViewDelegate>
{
UIImageView *thumbNailImageView;
UIWebView *mockUpWebView;
UIImage *viewImage;
}
@end
@implementation ThumbNail
-(void)webViewDidFinishLoad:(UIWebView *)webView {
thumbNailImageView.image = [self captureScreen:webView];
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
NSLog(@"Errorrr.............");
}
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"Got it");
return YES;
}
-(UIImage*)captureScreen:(UIWebView*) viewToCapture{
CGSize overallSize = CGSizeMake(mockUpWebView.frame.size.width, mockUpWebView.frame.size.width);
UIGraphicsBeginImageContext(viewToCapture.scrollView.contentSize);
viewToCapture.bounds = CGRectMake(0, 0, overallSize.width, overallSize.height);
while (viewToCapture.loading) {
[NSThread sleepForTimeInterval:0.1];
}
[viewToCapture.layer renderInContext:UIGraphicsGetCurrentContext()];
viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
-(void)getThumbNailForImageView:(UIImageView *)imageView{
thumbNailImageView = imageView;
NSString *urlAddress = @"https://in.yahoo.com/?p=us";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
CGRect bounds = [[UIScreen mainScreen] bounds];
mockUpWebView = [[UIWebView alloc]initWithFrame:bounds];
NSLog(@"bounds = %@",NSStringFromCGRect(bounds));
mockUpWebView.delegate = self;
[mockUpWebView loadRequest:requestObj];
}
@end
我试图通过调用getThumbNailForImageView来获取缩略图。