How to add CSS file to iphone project in xcode?

I am working on a web application for iphone, I created a new css project for the project, this css file does not affect the html file, but when I uploaded the css file to the host, it worked fine and in html style

what is the problem?

change 1

this element of the head.

css.css works fine and is correctly attached to html jquery.mobile-1.0.min.css NOT!

although both files exist on the same border

Onotha.com

 <link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.0.min.css" /> 

change 2

This is objectve-c code, I have an exception, I think in the last line of code

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [window makeKeyAndVisible]; NSString *path= [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:NO]; // [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]]; // NSString *path = [[NSBundle mainBundle] bundlePath]; // NSURL *baseURL = [NSURL fileURLWithPath:path]; // [webView loadHTMLString:htmlString baseURL:baseURL]; // load css styles NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"css/jquery.mobile-1.0.min.css" ofType:@"css"]; NSData *cssData = [NSData dataWithContentsOfFile:cssPath]; NSString *cssString = [[NSString alloc] initWithData:cssData encoding:NSASCIIStringEncoding]; // load js NSString *jsPath = [[NSBundle mainBundle] pathForResource:@"MyJS" ofType:@"js"]; NSData *jsData = [NSData dataWithContentsOfFile:jsPath]; NSString *jsString = [[NSString alloc] initWithData:jsData encoding:NSASCIIStringEncoding]; // compose full html page NSString *pageContent = [NSString stringWithFormat:@"%@%@%@", cssString, jsString, path]; [webView loadHTMLString:pageContent baseURL:baseURL]; return YES; } 

edit 3

I got this after using the code posted by Srikar screen shot

+4
source share
2 answers

You can load CSS from the local project directory.

 NSString *path = [[NSBundle mainBundle] bundlePath]; NSURL *baseURL = [NSURL fileURLWithPath:path]; [webView loadHTMLString:htmlString baseURL:baseURL]; 

detail info check this site .

More complicated code here -

 // load css styles NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"MyCSS" ofType:@"css"]; NSData *cssData = [NSData dataWithContentsOfFile:cssPath]; NSString *cssString = [[NSString alloc] initWithData:cssData encoding:NSASCIIStringEncoding]; // load js NSString *jsPath = [[NSBundle mainBundle] pathForResource:@"MyJS" ofType:@"js"]; NSData *jsData = [NSData dataWithContentsOfFile:jsPath]; NSString *jsString = [[NSString alloc] initWithData:jsData encoding:NSASCIIStringEncoding]; // compose full html page NSString *pageContent = [NSString stringWithFormat:@"%@%@%@", cssString, jsString, actualPageMarkup]; [webView loadHTMLString:pageContent baseURL:[NSURL URLWithString:@""]]; 

More here

+2
source

I don’t know if you have decided this, but I think you need to load the contents of the page on the Content page, not the path. Something like that:

 NSString *htmlString = [NSString stringWithContentsOfFile:path encoding:NSASCIIStringEncoding]; NSString *pageContent = [NSString stringWithFormat:@"%@%@%@", cssString, jsString, htmlString]; [webView loadHTMLString:pageContent baseURL:baseURL]; 
0
source

Source: https://habr.com/ru/post/1383387/


All Articles