• <bdo id='D8zAC'></bdo><ul id='D8zAC'></ul>
    <i id='D8zAC'><tr id='D8zAC'><dt id='D8zAC'><q id='D8zAC'><span id='D8zAC'><b id='D8zAC'><form id='D8zAC'><ins id='D8zAC'></ins><ul id='D8zAC'></ul><sub id='D8zAC'></sub></form><legend id='D8zAC'></legend><bdo id='D8zAC'><pre id='D8zAC'><center id='D8zAC'></center></pre></bdo></b><th id='D8zAC'></th></span></q></dt></tr></i><div id='D8zAC'><tfoot id='D8zAC'></tfoot><dl id='D8zAC'><fieldset id='D8zAC'></fieldset></dl></div>

    <small id='D8zAC'></small><noframes id='D8zAC'>

    <tfoot id='D8zAC'></tfoot>
        <legend id='D8zAC'><style id='D8zAC'><dir id='D8zAC'><q id='D8zAC'></q></dir></style></legend>

        UIWebView 中的字体大小与 iOS 字体大小不匹配

        Font sizes in UIWebView does NOT match iOS font size(UIWebView 中的字体大小与 iOS 字体大小不匹配)
        • <legend id='HCV6S'><style id='HCV6S'><dir id='HCV6S'><q id='HCV6S'></q></dir></style></legend>

            <small id='HCV6S'></small><noframes id='HCV6S'>

              <i id='HCV6S'><tr id='HCV6S'><dt id='HCV6S'><q id='HCV6S'><span id='HCV6S'><b id='HCV6S'><form id='HCV6S'><ins id='HCV6S'></ins><ul id='HCV6S'></ul><sub id='HCV6S'></sub></form><legend id='HCV6S'></legend><bdo id='HCV6S'><pre id='HCV6S'><center id='HCV6S'></center></pre></bdo></b><th id='HCV6S'></th></span></q></dt></tr></i><div id='HCV6S'><tfoot id='HCV6S'></tfoot><dl id='HCV6S'><fieldset id='HCV6S'></fieldset></dl></div>
                <bdo id='HCV6S'></bdo><ul id='HCV6S'></ul>
              • <tfoot id='HCV6S'></tfoot>

                    <tbody id='HCV6S'></tbody>
                  本文介绍了UIWebView 中的字体大小与 iOS 字体大小不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是一个 UILabel,上面写着关于".在 iOS 中设置为 17.7.

                  在它下面是一个 UIWebView,它也写着关于".也使用 css 设置为 17.7.

                  它们不匹配.

                  如何正确解决这个问题?

                  奇怪的是,在苹果自己的 UIWebView 中,大小基础不同?

                  要测试的 HTML...

                  <html><head><样式类型='文本/css'>身体 {边距:0px;字体系列:'SourceSansPro-Light';字体大小:FONTPOINTSpt;}html { -webkit-text-size-adjust:none;}</style></head><body leftmargin=0 topmargin=0>关于</body></html>

                  在设备或模拟器上的行为是相同的.

                  (注意,从

                  Here's a UILabel which says "About". Set at exactly 17.7 in iOS.

                  Below it a UIWebView which also says "About". Also set at exactly 17.7 using css.

                  They don't match.

                  How to fix this correctly?

                  It is bizarre that in Apple's own UIWebView, the size basis is different?

                  Html to test...

                  <html><head>
                  <style type='text/css'>
                  body {
                  margin: 0px;
                  font-family: 'SourceSansPro-Light';
                  font-size: FONTPOINTSpt;
                  }
                  html { -webkit-text-size-adjust:none; }
                  </style></head>
                  <body leftmargin=0 topmargin=0>
                  About
                  </body></html>
                  

                  Behavior is identical on device or simulator.

                  (Note, from here I learned the ratio is, perhaps 72.0/96.0.)

                  解决方案

                  If you want a 1 to 1 relationship between the font size that the UILabel uses and the font size that the UIWebView uses (via CSS) you have to use px instead of pt when defining the font size in your CSS.

                  Checkout this example HTML / CSS:

                  <html>
                      <head>
                          <style type='text/css'>
                              body {
                                 font-family: 'SourceSansPro-Regular';
                                 padding: 0
                              }
                              .point {
                                  font-size: 17pt
                              }
                              .pixel {
                                  font-size: 17px
                              }
                          </style>
                      </head>
                      <body>
                          <p class="point">About (17pt)<p>
                          <p class="pixel">About (17px)</p>
                      </body>
                  </html>
                  

                  When you add a UIWebView and a UILabel to your UIViewController and load the above HTML to the UIWebView and set the same font to the UILabel:

                  override func viewDidLoad() {
                      super.viewDidLoad()
                  
                      let webView = UIWebView(frame: CGRect(x: 25, y: 50, width:325 , height: 90))
                      view.addSubview(webView)
                  
                      let filePath = NSBundle.mainBundle().URLForResource("test", withExtension: "html")
                      webView.loadRequest(NSURLRequest(URL: filePath!))
                  
                      let label = UILabel(frame: CGRect(x: 25, y: 150, width: 325, height: 40))
                      label.font = UIFont(name: "SourceSansPro-Regular", size: 17)
                      label.text = "About (UILabel set to 17)"
                      view.addSubview(label)
                  }
                  

                  You get the following output:

                  这篇关于UIWebView 中的字体大小与 iOS 字体大小不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                  Resume game cocos2d(恢复游戏 cocos2d)
                  Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                  [ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)
                  Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)
                  How can I implement a virtual joystick for a cocos2d game outside the cocos2d environment?(如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?)
                    <legend id='0pIyz'><style id='0pIyz'><dir id='0pIyz'><q id='0pIyz'></q></dir></style></legend><tfoot id='0pIyz'></tfoot>
                    <i id='0pIyz'><tr id='0pIyz'><dt id='0pIyz'><q id='0pIyz'><span id='0pIyz'><b id='0pIyz'><form id='0pIyz'><ins id='0pIyz'></ins><ul id='0pIyz'></ul><sub id='0pIyz'></sub></form><legend id='0pIyz'></legend><bdo id='0pIyz'><pre id='0pIyz'><center id='0pIyz'></center></pre></bdo></b><th id='0pIyz'></th></span></q></dt></tr></i><div id='0pIyz'><tfoot id='0pIyz'></tfoot><dl id='0pIyz'><fieldset id='0pIyz'></fieldset></dl></div>

                      <bdo id='0pIyz'></bdo><ul id='0pIyz'></ul>
                    • <small id='0pIyz'></small><noframes id='0pIyz'>

                              <tbody id='0pIyz'></tbody>