iOS - 在HTML中更改iFrame标记中的宽度

时间:2015-01-17 12:11:06

标签: html ios css iframe uiwebview

我正在使用字符串请求加载UIWebView。在我的html字符串中,我有iframe标记,其中宽度值远大于预期。我怎样才能改变这个价值?

我的html字符串 -

<html> 
<head> 
<style type="text/css"> 
body {font-family:"Helvetica"; font-size: 18;} img {max-width: 100%; width: 100%; height: 100%};
</style> 
</head> 
<body><p><span style="font-size: 13px; line-height: 1.6em;">***Some Text***.</span></p>

<p>***Some Text***.</p>

<p><iframe allowfullscreen="" frameborder="0" height="360" src="//www.some-domain.com/embed/mwOFWJUOpv8" width="600"></iframe></p></body>

正如您所见,iframe标记中的 width = 600 ,这导致iPhone出现问题。我怎么能改变它?

我通过以下代码管理图片,我想管理iframe

到目前为止实施的代码 -

NSString *str = [NSString stringWithFormat:@"<html> \n"
                          "<head> \n"
                          "<style type=\"text/css\"> \n"
                         "body {font-family:\"%@\"; font-size: %@;} img {max-width: 100%%; width: 100%%; height: 100%%};\n"
                          "</style> \n"
                          "</head> \n"
                          "<body>%@</body> \n"
                         "</html>", @"Helvetica", [NSNumber numberWithInt:iWebViwFontSize], strHtml];
webViwNewsDescription loadHTMLString:str baseURL:baseURL];

1 个答案:

答案 0 :(得分:0)

尝试使用@media和目标屏幕宽度低于X px。例如700 px,并在CSS中添加:

.frame {
    -moz-transform: scale(0.5);
    -moz-transform-origin: 0 0;
    -o-transform: scale(0.5);
    -o-transform-origin: 0 0;
    -webkit-transform: scale(0.5);
    -webkit-transform-origin: 0 0;
}

编辑(0.5)值以满足您的需要。这将缩小iframe中的内容。我没有通过iPhone测试过,但它应该可以工作。

HTML:

<iframe class="frame"

编辑:

将此添加到您的CSS文件中。

@media screen and (max-width: 700px) {
    .frame {
        width:400px; /*or whatever width you'd like*/
        /*Here you can scale down the content in the iframe if it is too wide for the iframe*/
        -moz-transform: scale(0.5);
        -moz-transform-origin: 0 0;
        -o-transform: scale(0.5);
        -o-transform-origin: 0 0;
        -webkit-transform: scale(0.5);
        -webkit-transform-origin: 0 0;
    }
}

PS:如果你不熟悉CSS,我只是为了帮你解决这个问题:

普通 css中,添加:

.iframe{width:600px;}

然后所有屏幕的宽度都是600像素,但对于小于700像素的屏幕,其他CSS就可以了。

相关问题