如何在iphone中设置html + css添加
如何在iphone中设置html + css添加
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 = @"Ways Group max-height: 300px;%@"; // load the html into a web view NSURL *url = [NSURL fileURLWithPath:htmlContent]; [webView loadHTMLString:[NSString stringWithFormat:htmlString, htmlContent] baseURL:url];
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];
并且不要忘记在html中链接css
尝试这个:
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];