html没有按比例缩放为ios设备

时间:2015-05-15 08:22:34

标签: html ios css objective-c

我正在尝试在我的ios应用中将html页面嵌入到webView中。然而无论我做什么,我似乎无法使其适当缩放。正如您在当前应用程序中看到的那样,文本和图像超出了屏幕的宽度,这不是想要的结果。当我将所有宽度设置为100%并将scaleToFitPage设置为true时,为什么它不能正确缩放?

enter image description here

viewDidLoad中

    webView.scrollView.delegate = self
    webView.scrollView.showsHorizontalScrollIndicator = false
    webView.scalesPageToFit = true

HTML代码

<!-- template.html -->
<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8" />
    <style type="text/css">
        body{
            font-family: 'PT Sans';
            margin-left:0;
            margin-right:0;
            margin-top: 0;
            width: 100%;
        }
        .text_div{
            padding-left:10px;
            padding-right:100px;
            font-size:26px;
            width: 100%;
            word-wrap: break-word;
            -moz-box-sizing: border-box;
            -webkit-box-sizing:
            border-box; box-sizing: border-box;

        }

    .text_div p {
         display: block;
         width: 100%;
         word-wrap: break-word;
         -moz-box-sizing: border-box;
         -webkit-box-sizing:
         border-box; box-sizing: border-box;
    }
    .title{
        font-size: 40px;
        padding-left:5px;
        word-wrap: break-word;
        padding-right: 10px;
          margin-top: 10px;
          width: 100%;
          -moz-box-sizing: border-box;
          -webkit-box-sizing:
          border-box; box-sizing: border-box;
    }
    .main_image {
        width: 100%;
        height: 300px;
        background-size: cover;
        background-position: center; 
    }
    .main_image img{
        width: auto;
        height: auto;

    }
    </style>
</head>
<body>

   <div class="main_image" style="background-image:url([[[main_image]]])" title="[[[alt_desc]]]"></div>
   <p class="title">[[[title]]]</p>
   <div class="text_div">
        <p>[[[full_text]]]</p>
   </div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

UIWebView * webView = [[UIWebView alloc] initWithFrame:self.View.frame];

NSURL * targetURL = [NSURL fileURLWithPath:html_file_url];

NSURLRequest * request = [NSURLRequest requestWithURL:targetURL];

webView.scalesPageToFit = YES;

webView.scrollView.maximumZoomScale = 10.0;

webView.scrollView.minimumZoomScale = 1.0;

webView.backgroundColor = [UIColor whiteColor];

[self.view addSubview:webView];

[webView loadRequest:request];