2009-05-11 3 views
2

UIWebView에 대해 여기에 언급 된대로 Why does UIWebView shrink images? 메타보기 포트를 사용하고 있습니다. 이 형식은 세로 형식으로 좋으며 이상한 스케일링을 보완 할 필요가 없습니다. 그러나 일단 가로 방향으로 회전하면 추가 너비를 이용할 수 없습니다. 의미, 나는 조경을 위해 단 하나 선으로 더 많은 텍스트를 맞추고 싶다. 모든 것은 1.0으로 크기가 유지됩니다. 뷰포트를 회전시 .75 배율로 변경하고 세로로 1.0 배로 변경하는 방법이 있습니까?뷰포트로 UIWebview 가로 서식

답변

0

이 함수는 UIWebView 크기가 조절 될 때 뷰포트 폭을 설정하기 위해 작성했습니다. 너비가 아닌 다른 뷰포트 속성을 쉽게 설정할 수 있습니다.

-(NSString *) setViewportWidth:(CGFloat)inWidth { 
    NSString *result = [_webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"(function (inWidth) { " 
     "var result = ''; " 
     "var viewport = null; " 
     "var content = 'width = ' + inWidth; " 
     "var document_head = document.getElementsByTagName('head')[0]; " 
     "var child = document_head.firstChild; " 
     "while (child) { " 
      "if (null == viewport && child.nodeType == 1 && child.nodeName == 'META' && child.getAttribute('name') == 'viewport') { " 
       "viewport = child; " 
       "content = child.getAttribute('content'); " 
       "if (content.search(/width\\s=\\s[^,]+/) < 0) { " 
        "content = 'width = ' + inWidth + ', ' + content; " 
       "} else { " 
        "content = content.replace(/width\\s=\\s[^,]+/ , 'width = ' + inWidth); " 
       "} " 
      "} " 
      "child = child.nextSibling; " 
     "} " 
     "if (null != content) { " 
      "child = document.createElement('meta'); " 
      "child.setAttribute('name' , 'viewport'); " 
      "child.setAttribute('content' , content); " 
      "if (null == viewport) { " 
       "document_head.appendChild(child); " 
       "result = 'append viewport ' + content; " 
      "} else { " 
       "document_head.replaceChild(child , viewport); " 
       "result = 'replace viewport ' + content; " 
      "} " 
     "} " 
     "return result; " 
    "})(%d)" , (int)inWidth]]; 

    return result; 
}