HTML Content fit in UIWebview without zooming out

后端 未结 8 827
夕颜
夕颜 2020-11-27 12:21

I am making use of the UIWebView to render some HTML. However, although the width of my webview is 320 my HTML is still shown full width and can be scrolled hor

8条回答
  •  日久生厌
    2020-11-27 12:50

    Typically, you should use the viewport meta tag. But its use is very erratic, mostly if you want a cross platform web page.

    It also depends of what content and css you have.

    For my iPhone homepage, which must auto-resize from portrait to lanscape, I use this :

    
    

    If you need special resize, you can also use the event :

    
    

    with the corresponding funciton in your javascript :

    function updateOrientation() {
      if(Math.abs(window.orientation)==90)
          // landscape
      else
          // portrait   
    }
    

    EDIT :

    Seeing you page source, it seems you made it with a web editor, don't you ?

    Ok, I understand. Your main div has a width of 600px. The iphone screen resolution is 320x480. 600 > 320 so it exceeds the screen bounds.

    Now, let's make some simple operations:

    320 / 600 = 0.53
    480 / 600 = 0.8
    

    So you want to zoom out 0.5 times minimum and 0.8 times maximum. Lets change the viewport :

     
    

提交回复
热议问题