Set loading gif in UIWebView while it's loading
I'm searching for an easy method to d开发者_JAVA百科isplay a custom loading .gif or another image as long as a UIWebView is still loading the page.
I know I have to do it in
– webViewDidStartLoad:(UIWebView *)webView
But how do I load the image?
try this :
– webViewDidStartLoad:(UIWebView *)webView {
UIImageView *animatedImages;
NSMutableArray *imageArray;
// Array to hold jpg images
imageArray = [[NSMutableArray alloc] initWithCapacity:IMAGE_COUNT];
// Build array of images, cycling through image names
for (int i = 0; i < IMAGE_COUNT; i++)
[imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"yourGifImage%d.jpg", i]]];
// Animated images - centered on screen
animatedImages = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,IMG_HEIGHT,IMG_WIDTH)];
animatedImages.center = self.webView.center;
animatedImages.animationImages = [NSArray arrayWithArray:imageArray];
// One cycle through all the images takes 1 seconds
animatedImages.animationDuration = 1.0;
// Repeat forever
animatedImages.animationRepeatCount = 0;
animatedImages.tag = 1;
[animatedImages startAnimating];
// Add to webview
[self.webView addSubview:animatedImages];
}
and in webViewDidFinishLoad:
method remove it from superview
- (void)webViewDidFinishLoad:(UIWebView *)webView {
UIView * removeAminatingImages = [self.webView viewWithTag:1];
[removeAminatingImages removeFromSuperview];
}
精彩评论