zoukankan      html  css  js  c++  java
  • 使用webview加载html图片、表单超屏幕问题

    webView加载html代码时,使用webView自带的 scalesPageToFit 

    可以解决图片所带来的超过屏幕问题;但是,所带来的问题就是文字变小了,怎样让图片边小,并且文字还是原来html里大小?

    只需加上一段代码就OK。

     [self.webView loadHTMLString:[NSString stringWithFormat:@"<!DOCTYPE html><html><style type="text/css">img{ %.fpx !important; height:%.fpx !important; margin:0 !important;padding:0 !important;left:0 !important;}table{ %.fpx !important; margin:0 !important;padding:0 !important;left:0 !important;right:0 !important;}</style><head><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"></head><body>%@</body></html>",Width - 80, Width - 20, Width - 30,_detial.tznr] baseURL:nil];

        }

    在 loadHTMLString后面加上<!DOCTYPE html><html><style type="text/css">img{ %.fpx !important; height:%.fpx !important; margin:0 !important;padding:0 !important;left:0 !important;}table{ %.fpx !important; margin:0 !important;padding:0 !important;left:0 !important;right:0 !important;}</style><head><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"></head><body>%@</body></html>

    就可以了;主要是 img{ %.fpx !important; height:%.fpx !important; margin:0 !important;padding:0 !important;left:0 !important;}table{ %.fpx !important; margin:0 !important;padding:0 !important;left:0 !important;right:0 !important;}

    img{ %.fpx !important; height:%.fpx !important; margin:0 !important;padding:0 !important;left:0 !important;}是设置图片的宽高来覆盖img标签里的style,可以自行设置其宽高。

    而table{ %.fpx !important; margin:0 !important;padding:0 !important;left:0 !important;right:0 !important;}是设置表单的宽度适应手机屏幕,高度不用设置。

  • 相关阅读:
    【剑指offer】数组中重复的数字
    【剑指offer】数组中只出现一次的数字
    【linux】进程存储管理
    【linux】gdb调试
    【C/C++】快速排序的两种实现思路
    【C/C++】知识点
    【计算机网络】知识点记录
    【hadoop】mapreduce原理总结
    基于社交网络的情绪化分析IV
    Android studio 升级,不用下载完整版,完美更新到2.0
  • 原文地址:https://www.cnblogs.com/wujie123/p/6284961.html
Copyright © 2011-2022 走看看