ozd
ozd

Reputation: 1284

Equivalent to UIWebView's paginationMode on WKWebView

I'm changing a huge app that uses a lot of UIWebViews to use WKWebViews.

The app used to have this line paginationMode = .rightToLeft but WKWebView doesnt have this feature.

How can I get the UIWebView's right to left pagination in WKWebView?

Upvotes: 2

Views: 1222

Answers (1)

ozd
ozd

Reputation: 1284

Found it - I added this to my css file

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

Watch out about WKWebview ignoring parts of your css... in that case add this as a prefix to your Html string -

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

or via helper method in an WKWebview extension

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)
    }

make sure you add the right baseURL - in my case it is -

Bundle.main.bundleURL

Upvotes: 3

Related Questions