首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

webView 扫除背景和<> 等特殊字符的自动转换

2013-03-27 
webView 清除背景和 等特殊字符的自动转换- (void)viewDidLoad{??? [super viewDidLoad]??? // Do any

webView 清除背景和<> 等特殊字符的自动转换

- (void)viewDidLoad
{
??? [super viewDidLoad];
??? // Do any additional setup after loading the view, typically from a nib.
???
??? NSString *tempString = @"&lt;div&gt;sdfsdfsdf&lt;/div&gt"; //这种形式他会自动帮我们变成<>
??? NSString *tempString2 = @"<div>sdfsdfsdf</div>"; //这种形式他会自动帮我们去掉<div>等。
??? [self.myWebView loadHTMLString:tempString2 baseURL:nil];
??? self.myWebView.backgroundColor = [UIColor clearColor];
??? [self clearWebViewBackgroundWithColor];
??? self.myWebView.opaque = NO;
}
- (void)clearWebViewBackgroundWithColor{//下面这个方法是去除滚动的时候的背景。
??? NSLog(@"%d===",[[self.myWebView subviews]count]);
???? NSLog(@"%d===",[[[[self.myWebView subviews]objectAtIndex:0]subviews]count]);
???
??? for (UIView *view in [self.myWebView subviews]){
??????? if ([view isKindOfClass:[UIScrollView class]]){
??????????? for (UIView *shadowView in view.subviews){
??????????????? // 上下滚动出边界时的黑色的图片 也就是拖拽后的上下阴影
??????????????? if ([shadowView isKindOfClass:[UIImageView class]]){
??????????????????? shadowView.hidden = YES;
??????????????? }
??????????? }
??????? }
??? }
}

?

?

?

?

改变UIwebView 的字体颜色和大小。

?

?NSString *tempString2 = @"<div>sdfsdfsdf</div>";
???
??? NSString *jsString = [NSString stringWithFormat:@"<html> \n"
????????????????????????? "<head> \n"
????????????????????????? "<style type="text/css"> \n"
????????????????????????? "body {font-size: %d; font-family: "%@"; color: %@;font-weight:bold;}\n"
????????????????????????? "</style> \n"
????????????????????????? "</head> \n"
????????????????????????? "<body>%@</body> \n"
????????????????????????? "</html>", 33, @"Arail", @"red", tempString2];
??? [self.myWebView loadHTMLString:jsString baseURL:nil];

热点排行