Skip to content

Instantly share code, notes, and snippets.

@Blackjacx
Created May 15, 2013 15:04
Show Gist options
  • Save Blackjacx/5584658 to your computer and use it in GitHub Desktop.
Save Blackjacx/5584658 to your computer and use it in GitHub Desktop.
Loading HTML Resource Into UIWebView
- (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