2013-06-25 1 views
3

comment définir le code html + css ajouter dans l'iphonecomment définir le code html + css ajouter dans l'iPhone

webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0,320,458)]; 
    webView.delegate=self; 
    [self.view addSubview:webView]; 


    // HTML files are stored in the main bundle 
    NSBundle *bundle = [NSBundle mainBundle]; 
    NSString *path = [bundle bundlePath]; 

    NSString *filename = @"index"; 
    NSString *fullPath = [NSBundle pathForResource:filename ofType:@"html" inDirectory:path]; 
    [fullPath stringByReplacingOccurrencesOfString:@"/" withString:@"_"]; 

    // load a HTML from a file 
    // NSString *chapter_filename = [NSString stringWithFormat:@"Section%@", filename]; 
    // NSString *sectionHTMLPath = [[NSBundle mainBundle] pathForResource:fullPath ofType:@"html"]; 

    NSString* htmlContent = [NSString stringWithContentsOfFile:fullPath encoding:NSUTF8StringEncoding error:nil]; 

    // add a generic template and the css file directive 
    NSString* htmlString = @"<!doctype html xmlns:[email protected]\"http://ogp.me/ns/fb#\"><head><meta charset=\"utf-8\"><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\"><title>Ways Group</title><meta name=\"description\" content=\"An very basic example of how to use the Wookmark jQuery plug-in.\"><meta name=\"author\" content=\"Christoph Ono\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><link href=\"landing-page/css/jquerysctipttop.css\" rel=\"stylesheet\" type=\"text/css\"><!-- Link to the built CSS --><link rel=\"stylesheet\" href=\"landing-page/css/modal.css\"><link rel=\"stylesheet\" href=\"css/main.css\"><link rel=\"stylesheet\" href=\"css/style.css\"><link rel=\"stylesheet\" href=\"css/menu.css\" type=\"text/css\" media=\"screen\" /><!-- CSS Reset --><link rel=\"stylesheet\" href=\"css/reset.css\"><link href=\"css/social-likes.css\" rel=\"stylesheet\"><script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js\"></script><script src=\"js/social-likes.js\"></script><!-- Styling for your grid blocks --><style type=\"text/css\">max-height: 300px;</style></head><body>%@</body></html>"; 
// load the html into a web view 

NSURL *url = [NSURL fileURLWithPath:htmlContent]; 
[webView loadHTMLString:[NSString stringWithFormat:htmlString, htmlContent] baseURL:url]; 
+0

Peut-être juste '[NSString stringWithFormat: @"% @ ", htmlString]'? – Mat

Répondre

8
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"html" inDirectory:nil]; 
NSString *htmlString = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil]; 
NSURL *Url = [NSURL fileURLWithPath:htmlFile]; 
[WebView loadHTMLString:htmlString baseURL:Url]; 

Et ne pas oublier pour lier le CSS en html

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

essayez ceci:

NSString *path = [[NSBundle mainBundle] bundlePath]; 
NSURL *baseURL = [NSURL fileURLWithPath:path]; 
CGRect frame2ref = CGRectMake(0, 45, 320,380); 
webview1 = [[[UIWebView alloc] initWithFrame:frame2ref] autorelease]; 
[webview1 loadHTMLString:ref baseURL:baseURL]; 
+0

ce code ne convient pas du code principal – Charlie

Questions connexes