css file not loading in UIWebView in iOS?

0 votes
380 views
asked Oct 17, 2014 in Objective C by jonathan (3,105 points)

hi

  I am trying to load the css file from local I stored all the html,CSS and js files in Source folder

In the html page i am using the following line to include the css..

<link rel="stylesheet" type="text/css" href="style.css">

 

But its not working properly while running in device..

 

thanks

 

1 Answer

0 votes
answered Oct 17, 2014 by john (4,220 points)

Hi

   Its very simple you should add BaseUrl as local fould where you are kept all the html file.

Might be code should like this..

NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"Source/index" ofType:@"html"];

    

    NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];

    

    NSString *htmlFilePath = [[NSBundle mainBundle] bundlePath];

    NSURL *baseURL = [NSURL fileURLWithPath:[htmlFilePath stringByAppendingString:@"/Source"]];

    

    [_mainWebView loadHTMLString:htmlString baseURL:baseURL];

...