UIWebView에 대해 "scalesPageToFit"속성을 YES로 설정했습니다. 점점 확대되지만 페이지가로드 될 때 내용이 꼬집음없이 읽을 수없는 작은 글꼴로 표시됩니다. 확대/축소 배율을 기본값으로 설정할 수 있습니까?UIWebView 확대/축소
1
A
답변
3
이
당신이 표시되는 HTML을 통해 설정 제어가있는 경우
그냥<head>
내부
<meta name="viewport" content="width=device-width;initial-scale=1.0">
을 넣어 그런 다음있는 UIWebView 자체를로드하는 사이트 ...에 대한 자세한입니다.
그렇지 않은 경우 : 당신은있는 UIWebView에 자바 스크립트를 삽입하고 실행, 그래서 작은 코드를 사용하여 메타 태그를 삽입 할 수있는 쉬운 방법이 있습니다 :
NSString *result = [webView stringByEvaluatingJavaScriptFromString:
[NSString stringWithFormat:@"var result = '';"
"var viewport = null;"
"var content = null;"
"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;"
" viewport.setAttribute('content' , 'width=device-width;initial-scale=1.0');"
" result = 'fixed meta tag';"
" }"
" child = child.nextSibling;"
"}"
"if (null == viewport)"
"{"
" var meta = document.createElement('meta');"
" meta.setAttribute('name' , 'viewport');"
" meta.setAttribute('content' , 'width=device-width;initial-scale=1.0');"
" document_head.appendChild(meta);"
" result = 'added meta tag';"
"}"
]
];
참고 니펫 죽일 것입니다, HTML 코드의 작성자가 만든 뷰포트 설정 ... 그래서 이상한 결과가 발생할 수 있습니다.
+0
JS의 더미 대신'var viewport = document.querySelector ('head meta [name = viewport]')는 어떻습니까? – andytuba
관련 문제
- 1. UIWebView
- 2. Safari의 UIWebView 링크를여시겠습니까? UIWebView 대리자 게재 위치
- 3. UIwebview 지연로드
- 4. iPad의 UIWebview
- 5. UIWebView 재사용
- 6. UIWebView 오류
- 7. 있는 UIWebView
- 8. UINavigationController의 UIWebView
- 9. UIWebView SetFrame
- 10. UIWebView stringByEvaluatingJavaScriptFromString
- 11. UIWebView 현지화
- 12. 있는 UIWebView
- 13. 있는 UIWebView
- 14. setKeyboardAppearance가있는 UIWebView
- 15. 가있는 UIWebView
- 16. Appearing UIWebView
- 17. UIWebView & ShouldStartLoadWithRequest
- 18. UIWebView CGPDFDocumentRef
- 19. 방법의 UIWebView
- 20. UIWebview Popup
- 21. UIPopoverController의 UIWebView
- 22. UIWebView 캐싱하기
- 23. iOS의 UIWebView
- 24. UIWebView - iPhone
- 25. 있는 UIWebView
- 26. UIWebView 마스킹하기
- 27. 가있는 UIWebView
- 28. 동적으로있는 UIWebView
- 29. UIWebView ScalePagesToFit?
- 30. 링크가있는 UIWebView
정확하게 원하는 것은 HTML 콘텐츠를로드 할 때 100 % 확대/축소가되어야합니다. 확대하기 위해 집기를 확대 할 때 확대해야합니다. – Bharathi
게시 한 코드를 사용해 보셨습니까? 잠깐만 - 문제를 해결할 것입니다! – dom
'scalesPageToFit = YES' 그것은 작동하지만 기본 컨텐츠 크기를 변경합니다. [내 답변을보십시오. 도움이 될 것입니다.] (http://stackoverflow.com/questions/7134576/enable-zooming-pinch-on-uiwebview/23971234 # 23971234) – iPatel