Code Monkey home page Code Monkey logo

easywebview's Introduction

Version License Platform Swift

Introduction

EasyWebView enables application to use WKWebView easily, in UIViewController or UITableViewCell.

Features

  • one line code to use WKWebView by loading url or html string.
  • smart and easy to adjust height of WebView in UITableViewCell.
  • easy and safe to use ScriptMessageHandler.
  • support common WKWebView feature.

Installation

Requirements

  • Swift 4.2
  • iOS 9.0

Cocoapods

EasyWebView is available through CocoaPods. To install it, simply add the following line to your Podfile:

platform :ios, '9.0'
pod "EasyWebView"

If you want to load http url, Don't forget the Privacy Description in info.plist.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Usage

Use WebViewController

class ViewController: UIViewController {
    func pushToWebViewController() {
        pushToWebByLoadingURL("google.com", title: "Google")
    }
}

Override WebViewController

class CustomWebViewController: WebViewController {
    override var isShowProgressView: Bool { return false }
    override var isShowTitle: Bool { return false }
}

Use WebViewCell

class ViewController: UITableViewController {
    private var webCellHeight: CGFloat = 300

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.register(WebViewCell.self, forCellReuseIdentifier: String(describing: WebViewCell.self))
    }
}

extension ViewController {
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return webCellHeight
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withClass: WebViewCell.self, for: indexPath)
        // test url and scriptNames
        cell.setupURLString("https://test.com", delegate: self, isAddObservers: true)
        cell.webView.addScriptMessageHandler(scriptNames: ["test"]) { (_, message) in
            print("😄: \(message.body)")
        }
        return cell
    }

    override func scrollViewDidScroll(_ scrollView: UIScrollView) {
        tableView.fixWebViewCellRenderingWhite()
    }
}

Author

Does your organization or project use EasyWebView? Please let me know by email. John, [email protected] .

License

EasyWebView is available under the MIT license.

easywebview's People

Contributors

alflix avatar jieyuanz24 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

easywebview's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.