簡體   English   中英

html無法針對iOS設備擴展

[英]html not proberly scaled for ios device

我正在嘗試將html頁面嵌入到ios應用程序的webView中。 但是,無論我做什么,我似乎都無法使其正確縮放。 正如您在當前應用程序上看到的那樣,文本和圖像超出了屏幕的寬度,這不是想要的結果。 當我將所有寬度都設置為100%並將scaleToFitPage設置為true時,它為什么不能正確縮放?

在此處輸入圖片說明

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>

UIWebView * webView = [[UIWebView分配] 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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM