SplashScreen With WebView In iPhone

In this application we will see how to WebView display after SplashScreen. So let see how it will worked.

Step 1: Open the Xcode, Create a new project using Window Base application. Give the application “SplashWithWeb”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Expand classes and notice Interface Builder created the AppDelegate class for you. Expand Resources and notice the template generated a separate nib, MainWindow.xib for the SplashWithWeb application.

Step 4: We need to add background resources in the resource folder. Give the resource name “1.png”.

Step 5: We need to add UIViewController class in the application. Select NewFile -> UIViewController sub class -> and give the class name “WebViewDisplay”.

Step 6: Open the SplashWithWebAppDelegate.h file and make the following changes:

 

#import <uikit/UIKit.h>
@class WebViewDisplay;
@interface SplashWithWebAppDelegate : NSObject {
WebViewDisplay *webViewDisplay;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet WebViewDisplay *webViewDisplay;
@end

 

 

Step 7: Select SplashWithWeb project from the Xcode , go to TARGETS -> SplashWithWeb -> Summary -> Launch images . Select the background image.

Step 8: In the SplashWithWebAppDelegate.m file make the following changes:

 

#import "SplashWithWebAppDelegate.h"
#import "WebViewDisplay.h"
@implementation SplashWithWebAppDelegate
@synthesize window=_window , webViewDisplay;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
webViewDisplay = [[WebViewDisplay alloc]initWithNibName:@"WebViewDisplay" bundle:[NSBundle mainBundle]];
[_window addSubview:webViewDisplay.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
}
- (void)applicationWillTerminate:(UIApplication *)application
{
}
- (void)dealloc
{
[_window release];
[super dealloc];
}
@end

 

 

Step 9: Open the WebViewDisplay.h file and make the following changes:

 

#import <uikit/UIKit.h>
@interface WebViewDisplay : UIViewController {
IBOutlet UIWebView *webDisplay;
}
@property(nonatomic,retain) UIWebView *webDisplay;
@end

 

 

Step 10: Double click the WebViewDisplay.xib file and open it to the Interface Builder. First drag the WebView from the library and place it to the view window. Connect File’s owner icon to the WebView and select webDisplay. Now save the .xib file and go back to the Xcode.

Step 11: WebViewDisplay.m file make the following changes in the file:

 

#import "WebViewDisplay.h"
@implementation WebViewDisplay
@synthesize webDisplay;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
NSString *urlAddress = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webDisplay loadRequest:requestObj];
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end

 

 

Step 12: Now compile and run the application on the simulator.

You can Download SourceCode from here