Fatih Lale
Fatih Lale

Reputation: 41

How to use Safari's Reading Mode on webView - Swift 3

He guys. I want the website to open in reading mode. I want it to open without unnecessary ads and buttons. How can I do that on webView. Sorry for my very bad English. Thanks.

Upvotes: 3

Views: 3178

Answers (2)

JillevdW
JillevdW

Reputation: 1127

UPDATE FOR SWIFT 4, iOS 11

The SFSafariViewController init function that takes an entersReaderIfAvailable parameter has been replaced by one that takes an SFSafariViewController.Configuration property. To get the old behaviour you can replace the code used in answers above by this:

let urlString = "http://www.google.com"
let url = URL(string: urlString)!
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = true
let safariVC = SFSafariViewController(url: url, configuration: config)
present(safariVC, animated: true, completion: nil)

This will do the trick!

Upvotes: 5

Fares Benhamouda
Fares Benhamouda

Reputation: 619

First thing you cannot enable "Reader" mode for WKWebView or UIWebView. You need to use SFSafariViewController

Then you need to set entersReaderIfAvailable to true when initializing the instance.

Here an example :

    let urlString = "http://google.com"
    let url = URL(string: urlString)
    let safariVC = SFSafariViewController(url: url!, entersReaderIfAvailable: true)
    present(safariVC, animated: true, completion: nil)

Upvotes: 3

Related Questions