在开发的过程中,经常遇到UIWebView,UIWebView需要适应手机屏幕的大小,如果直接让网页在手机上按照网页的大小进行等比例的缩放的话,网页上的文字就太小了,看不清楚,所以在开发的过程中,我们采用先让网页中的图片适应手机的屏幕大小,然后将网页中的文字填充进去,两行代码就可以搞定。
其中webTitle是我们需要添加的让网页适应的一段HTML,htmlIntroduceStr则是我们从服务器请求下来的html语句,然后将他们按照如下方式进行拼接,加载即可,不废话,直接上代码:
NSString *htmlIntroduceStr;
NSString *webTitle = @"<style type='text/css'> .tree{width:100%!important; height:auto!important; margin:0 auto 0} img { width:100%!important; height:auto !important; margin: 0px auto 0px;}; span { word-wrap: break-word; word-break: normal; } </style>";
NSString *webStr = [NSString stringWithFormat:@"<html><header>%@</header><body><div class='tree'>%@</div></body></html>", webTitle, htmlIntroduceStr];
[goodsIntroduceWebView loadHTMLString:webStr baseURL:[NSURL URLWithString:Base_Url]];