In your controller .h
@property (nonatomic, retain) UIImageView *loadingImageView;
In your .m controller
@synthesize loadingImageView; - (void)viewDidLoad { ... UIImageView *theLoadingImageView = [[UIImageView alloc] initWithFrame:webView.frame]; theLoadingImageView.image = [UIImage imageNamed:@"your_image.png"]; self.loadingImageView = theLoadingImageView; [theLoadingImageView release]; ... } - (void) webViewDidStartLoad:(UIWebView *)webView { [self.view addSubview:self.loadingImageView]; } - (void) webViewDidFinishLoad:(UIWebView *)webView { [self.loadingImageView removeFromSuperview]; }
EDIT 1:
If you want to show ActivityIndicatorView instead of a static image, here is a small helper class that I like to use:
LoadingIndicator.h
LoadingIndicator.m
#import "LoadingIndicator.h" #import <QuartzCore/QuartzCore.h> @implementation LoadingIndicator @synthesize labelMessage, activityIndicator; - (id)init { if (self = [super initWithFrame:CGRectMake(25, 130, 270, 100)]) { // Vue self.backgroundColor = [UIColor blackColor]; self.alpha = 0.80; self.layer.cornerRadius = 5; // Label : message UILabel *theLabelMessage = [[UILabel alloc] initWithFrame:CGRectMake(15, 65, 240, 20)]; theLabelMessage.backgroundColor = [UIColor clearColor]; theLabelMessage.textColor = [UIColor whiteColor]; theLabelMessage.text = NSLocalizedString(@"Loading", @"Loading"); theLabelMessage.textAlignment = UITextAlignmentCenter; theLabelMessage.font = [UIFont boldSystemFontOfSize:16]; theLabelMessage.adjustsFontSizeToFitWidth = YES; self.labelMessage = theLabelMessage; [self addSubview:theLabelMessage]; [theLabelMessage release]; // Activity Indicator UIActivityIndicatorView *theActivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; theActivityIndicator.frame = CGRectMake(115, 15, 40, 40); self.activityIndicator = theActivityIndicator; [self addSubview:theActivityIndicator]; [theActivityIndicator release]; } return self; } - (void)show:(NSString *)theMessage { self.labelMessage.text = theMessage; [self.activityIndicator startAnimating]; self.hidden = NO; [self.superview bringSubviewToFront:self]; [self refreshPosition]; } - (void)hide { [self.activityIndicator stopAnimating]; self.hidden = YES; } - (void)refreshPosition { self.center = self.superview.center; } - (void)dealloc { self.labelMessage = nil; self.activityIndicator = nil; [super dealloc]; } @end
Then in your view.h
In your view .m
Finally, in your doing WebView:
- (void) webViewDidStartLoad:(UIWebView *)webView { [(YourView *)self.view showLoadingIndicator:@"Loading"]; } - (void) webViewDidFinishLoad:(UIWebView *)webView { [(YourView *)self.view hideLoadingIndicator]; }
It will look something like this:

source share