Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alflix/easywebview
use WKWebView easily!
https://github.com/alflix/easywebview
webview wkwebview wkwebview-javascript-bridge
Last synced: about 2 months ago
JSON representation
use WKWebView easily!
- Host: GitHub
- URL: https://github.com/alflix/easywebview
- Owner: alflix
- License: apache-2.0
- Created: 2019-05-22T15:52:55.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-13T15:57:32.000Z (almost 5 years ago)
- Last Synced: 2024-10-20T11:18:53.232Z (2 months ago)
- Topics: webview, wkwebview, wkwebview-javascript-bridge
- Language: Swift
- Homepage:
- Size: 462 KB
- Stars: 12
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Version](https://img.shields.io/cocoapods/v/EasyWebView.svg?style=flat)](http://cocoapods.org/pods/EasyWebView)
[![License](https://img.shields.io/cocoapods/l/EasyWebView.svg?style=flat)](http://cocoapods.org/pods/EasyWebView)
[![Platform](https://img.shields.io/cocoapods/p/EasyWebView.svg?style=flat)](http://cocoapods.org/pods/EasyWebView)
![Swift](https://img.shields.io/badge/%20in-swift%205.0-orange.svg)## 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](http://cocoapods.org). To install it, simply add the following line to your Podfile:
```ruby
platform :ios, '9.0'
pod "EasyWebView"
```> If you want to load http url, Don't forget the Privacy Description in `info.plist`.
```xml
NSAppTransportSecurityNSAllowsArbitraryLoads
```
## Usage
**Use WebViewController**
```swift
class ViewController: UIViewController {
func pushToWebViewController() {
pushToWebByLoadingURL("google.com", title: "Google")
}
}
```**Override WebViewController**
```swift
class CustomWebViewController: WebViewController {
override var isShowProgressView: Bool { return false }
override var isShowTitle: Bool { return false }
}
```**Use WebViewCell**
```swift
class ViewController: UITableViewController {
private var webCellHeight: CGFloat = 300override 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.