美文网首页
Webview设置字体大小和字体缩放

Webview设置字体大小和字体缩放

作者: TyroneTang | 来源:发表于2017-11-03 00:27 被阅读22次

var test=test.replace(/font-size:\w+;?/g,'');

https://zhidao.baidu.com/question/1607960261788848147.html?fr=iks&word=iOS+%B7%C5%B4%F3UIWebview%D6%D0%B5%C4%CE%C4%D7%D6&ie=gbk

修改UIWebView控件中字体的样式:
NSString *htmlString = [NSString stringWithContentsOfFile:self.webPath encoding:NSUTF8StringEncoding error:nil];
UIFont *font = [UIFont systemFontOfSize:12];
NSString *newHtmlString = [NSString stringWithFormat:@"<font face='%@' >%@", font.fontName,htmlString];
[self.myWebView loadHTMLString:newHtmlString baseURL:[NSURL URLWithString:self.webPath]];

修改UIWebView控件中字体的大小:
NSString *str = @"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '60%'";
[self.myWebView stringByEvaluatingJavaScriptFromString:str];

//给scrollview添加头视图

 _htmlWebView.scrollView.contentInset = UIEdgeInsetsMake(40, 0, 0, 0);
_titleLabel = [[UILabel alloc] init];
[_htmlWebView.scrollView addSubview:_titleLabel];
   _titleLabel.frame = CGRectMake(0, -40, _htmlWebView.frame.size.width, 40);
[_htmlWebView.scrollView addSubview:_titleLabel];
 _titleLabel.text = @"标题";

相关文章

网友评论

      本文标题:Webview设置字体大小和字体缩放

      本文链接:https://www.haomeiwen.com/subject/gmrzpxtx.html