## Description
The CruiserWebViewController is a powerful and flexible web view controller for iOS apps. It provides an easy way to display web content within your app, with convenient customization options. With a simple implementation, you can enhance the browsing experience for your users.
## Key Features
– **Easy Integration**: Integrate the CruiserWebViewController seamlessly into your app with minimal effort.
– **Customizable Interface**: Customize the web view controller’s appearance to match your app’s design.
– **Navigation Controls**: Enable or disable back, forward, and reload buttons for easy navigation.
– **Progress Indicator**: Display a progress indicator to show the loading status of web pages.
– **Address Bar**: Show or hide the address bar for easy access to the URL.
– **Dark Mode Support**: Support for dark mode, ensuring a consistent user experience across iOS versions.
– **JavaScript Interaction**: Communicate between web content and native iOS code using JavaScript and delegate methods.
## Installation
You can install CruiserWebViewController using [CocoaPods](https://cocoapods.org/) by adding the following line to your Podfile:
“`ruby
pod ‘CruiserWebViewController’
“`
Alternatively, you can manually add the CruiserWebViewController source files to your project.
## Usage
To use CruiserWebViewController in your app, follow these steps:
1. Import the CruiserWebViewController module in your view controller:
“`swift
import CruiserWebViewController
“`
2. Initialize an instance of CruiserWebViewController with the desired URL:
“`swift
let webView = CruiserWebViewController(urlString: “https://www.example.com”)
“`
3. Customize the appearance and behavior of the web view controller using the available properties and methods.
4. Present the web view controller modally or embed it in a navigation controller to integrate it into your app’s navigation flow:
“`swift
// Present web view controller modally
present(webView, animated: true, completion: nil)
// Embed web view controller in a navigation controller
let navigationController = UINavigationController(rootViewController: webView)
present(navigationController, animated: true, completion: nil)
“`
## Customization
The CruiserWebViewController allows for easy customization. Below are some examples:
– **Appearance Customization**: Customize the background color, bar tint color, and status bar style.
“`swift
webView.view.backgroundColor = .white
webView.barTintColor = .black
webView.statusBarStyle = .lightContent
“`
– **Navigation Controls Customization**: Show or hide the back, forward, or reload buttons.
“`swift
webView.showBackButton = true
webView.showForwardButton = true
webView.showReloadButton = false
“`
– **Address Bar Customization**: Show or hide the address bar.
“`swift
webView.showAddressBar = true
“`
## Communication with Web Content
The CruiserWebViewController supports JavaScript interaction and provides delegate methods for communication between web content and native iOS code. Here’s an example:
Implement the `CruiserWebViewDelegate` protocol in your view controller:
“`swift
class ViewController: UIViewController, CruiserWebViewDelegate {
// …
// Your code here
// …
func webView(_ webView: CruiserWebViewController, didReceiveMessage message: String) {
// Handle received message from web content
}
func webView(_ webView: CruiserWebViewController, shouldSendMessage message: String) -> Bool {
// Determine whether to allow sending a message to web content
return true
}
}
“`
Assign your view controller as the delegate of the CruiserWebViewController:
“`swift
webView.delegate = self
“`
Now you can send and receive messages between the web content and your native iOS code using JavaScript:
“`swift
// Sending a message to web content
webView.sendMessageToWebContent(“Hello, web content!”)
// Receiving a message from web content (implemented in delegate method)
func webView(_ webView: CruiserWebViewController, didReceiveMessage message: String) {
print(“Received message: \(message)”)
}
“`
## Requirements
The CruiserWebViewController requires:
– iOS 10.0 or later
– Swift 5.0 or later
## License
The CruiserWebViewController is released under the [MIT License](https://opensource.org/licenses/MIT), allowing you to use and modify the library in your projects.
For more details, refer to the [GitHub repository](https://github.com/example/repository) of CruiserWebViewController.