Created
May 15, 2013 15:04
-
-
Save Blackjacx/5584658 to your computer and use it in GitHub Desktop.
Loading HTML Resource Into UIWebView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)showHTMLRessourceInWebView:(BOOL)animated | |
{ | |
// Load html data from main bundle | |
NSString * filePath = [[NSBundle mainBundle] | |
pathForResource:@"<RESOURCE_NAME>" | |
ofType:@"html"]; | |
NSData * htmlData = [NSData dataWithContentsOfFile:filePath]; | |
if( !htmlData ) { | |
NSLog(@"There is an error in loading the html data..."); | |
} | |
NSString * htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding]; | |
if( !htmlData ) { | |
NSLog(@"There is an error converting the html data to NSString..."); | |
} | |
NSString * path = [[NSBundle mainBundle] bundlePath]; | |
NSURL * baseURL = [NSURL fileURLWithPath:path]; | |
// Initialize web view | |
UIViewController *parentController = [UIViewController new]; | |
CGSize screenSize = [[UIScreen mainScreen] bounds].size; | |
CGFloat statusbarHeight = [UIApplication sharedApplication].statusBarFrame.size.height; | |
CGRect webViewFrame = CGRectMake(0,0, | |
screenSize.width, | |
screenSize.height - statusbarHeight); | |
UIWebView *webView = [[UIWebView alloc] initWithFrame:webViewFrame]; | |
for(UIView * potentialScrollView in webView.subviews) | |
{ | |
if( [potentialScrollView isKindOfClass:[UIScrollView class]] ) | |
{ | |
[(UIScrollView*)potentialScrollView | |
setIndicatorStyle:UIScrollViewIndicatorStyleWhite]; | |
} | |
} | |
[webView setTag:WEBVIEW_TAG]; | |
[webView setDelegate:self]; | |
[webView loadHTMLString:htmlString baseURL:baseURL]; | |
[parentController.view addSubview:webView]; | |
[webView release]; | |
[self presentModalViewController:parentController animated:animated]; | |
[parentController release]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment