I am loading a local html page by this code:
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"title" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];
...it is loading perfectly. I have added the link tag to load the local css file which is added in the project as well but it does load the page as expected.
<head>
<link media="only screen and (max-device-width: 480px)" href="/style.css" type= "text/css" rel="stylesheet" />
</head>
But when i load the local html page with css from the server it loads perfectly.
<head>
<link href="http://somehitng.com/stylesheets/style.css" media="screen" rel="stylesheet" type="text/c开发者_如何学Pythonss" />
</head>
Can anyone help me what I am doing wrong?
You need to set the base URL of the web view to the location where the HTML file is, so local link references work.
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]];
精彩评论