正如刘大卫(David Liu)所说,UIWebview是一条路要走.我建议一些人单独构建HTML字符串,然后将其传递给UIWebView.此外,我会使用[webView setBackgroundColor:[UIColor clearColor]]
使背景透明,这样你就可以更容易地让事情看起来像它们应该的样子.
下面是一个代码示例:
- (void) createWebViewWithHTML{
//create the string
NSMutableString *html = [NSMutableString stringWithString: @"<html><head><title></title></head><body style=\"background:transparent;\">"];
//continue building the string
[html appendString:@"body content here"];
[html appendString:@"</body></html>"];
//instantiate the web view
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.frame];
//make the background transparent
[webView setBackgroundColor:[UIColor clearColor]];
//pass the string to the webview
[webView loadHTMLString:[html description] baseURL:nil];
//add it to the subview
[self.view addSubview:webView];
}
NOTE:
使用"NSMutableString"的好处是,您可以通过整个解析操作继续构建字符串,然后将其传递给"UIWebView",而"NSString"一旦创建就无法更改.