`

自定义UIWebView背景和每段首行缩进

阅读更多
自定义UIWebView背景和每段首行缩进
让UIWebView背景透明的方法,如下。

web_about.backgroundColor = [UIColor clearColor];
web_about.opaque = NO;

关键是在HTML里:
<body style="background-color: transparent">

//可以这样定义背景.
NSMutableString *string = [[[NSMutableString alloc] initWithString:htmlString] autorelease];
[string insertString:@"<body style=\"background-color:#FCF3E9;text-indent:2em;\">" atIndex:0];
[string appendString:@"</body>"];
NSLog(@"%@",string);
[webView loadHTMLString:string baseURL:nil];

#FCF3E9 可以通过取色器获得(该色为米黄色)
text-indent:2em 设置所有段落的首行缩进2格.
加载数据的时候,webView会显示一个白色的背景框,要去掉该框,我的做法是先将webView的frame设为Zero,在delegate的加载完成后再将frame设为原来大小.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics