3

how to set the html +css add in the 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:fb=@\"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];
4

2 回答 2

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];

And Don't forget to link the css in html

    <link rel="stylesheet" type="text/css" href="Sample.css">
于 2013-06-26T08:04:35.283 回答
0

try this:

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];
于 2013-06-25T08:29:08.783 回答