【问题标题】:Equivalent to UIWebView's paginationMode on WKWebView等效于 WKWebView 上 UIWebView 的 paginationMode
【发布时间】:2020-01-23 18:03:02
【问题描述】:

我正在将一个使用大量UIWebViews 的大型应用程序更改为使用WKWebViews。

该应用程序曾经有此行paginationMode = .rightToLeft 但WKWebView 没有此功能。

如何在 WKWebView 中获取 UIWebView 从右到左的分页?

【问题讨论】:

    标签: ios pagination wkwebview


    【解决方案1】:

    找到了—— 我将此添加到我的css 文件中

    body {
        overflow: -webkit-paged-x !important;
        direction: rtl !important;
    }
    

    注意 WKWebview 忽略部分 css... 在这种情况下,将此作为前缀添加到您的 Html 字符串 -

    "<meta name=\"viewport\" content=\"initial-scale=1.0\" />"
    

    或通过 WKWebview 扩展中的辅助方法

    open func loadHTMLStringForWKWebview(_ string: String, baseURL: URL?)
        {
            // without this line WKWebview may ignore part in your css file
            let headerString = "<meta name=\"viewport\" content=\"initial-scale=1.0\" />"
            loadHTMLString(headerString+string, baseURL: baseURL)
        }
    

    确保添加正确的 baseURL - 在我的情况下是 -

    Bundle.main.bundleURL
    

    【讨论】:

      猜你喜欢
      • 2014-12-05
      • 1970-01-01
      • 2013-09-01
      • 2017-11-25
      • 2018-03-29
      • 1970-01-01
      • 1970-01-01
      • 2020-01-12
      • 1970-01-01
      相关资源
      最近更新 更多