{"id":16948652,"url":"https://github.com/timoliver/towebcontentviewcontroller","last_synced_at":"2025-07-06T03:04:47.368Z","repository":{"id":33277477,"uuid":"152969791","full_name":"TimOliver/TOWebContentViewController","owner":"TimOliver","description":"A view controller to quickly render arbitrary local HTML content.","archived":false,"fork":false,"pushed_at":"2022-01-23T13:18:45.000Z","size":757,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-15T06:19:34.409Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TimOliver.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"timoliver","custom":"https://tim.dev/paypal"}},"created_at":"2018-10-14T12:08:31.000Z","updated_at":"2023-05-04T11:55:51.000Z","dependencies_parsed_at":"2022-08-07T20:17:36.286Z","dependency_job_id":null,"html_url":"https://github.com/TimOliver/TOWebContentViewController","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/TimOliver/TOWebContentViewController","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimOliver%2FTOWebContentViewController","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimOliver%2FTOWebContentViewController/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimOliver%2FTOWebContentViewController/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimOliver%2FTOWebContentViewController/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimOliver","download_url":"https://codeload.github.com/TimOliver/TOWebContentViewController/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimOliver%2FTOWebContentViewController/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263841596,"owners_count":23518484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T21:51:48.382Z","updated_at":"2025-07-06T03:04:47.348Z","avatar_url":"https://github.com/TimOliver.png","language":"Objective-C","funding_links":["https://github.com/sponsors/timoliver","https://tim.dev/paypal","https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=M4RKULAVKV7K8"],"categories":[],"sub_categories":[],"readme":"# TOWebContentViewController\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/TimOliver/TOWebContentViewController/master/screenshot.jpg\" width=\"500\" style=\"margin:0 auto\" /\u003e\n\u003c/p\u003e\n\n[![CI](https://github.com/TimOliver/TOWebContentViewController/workflows/CI/badge.svg)](https://github.com/TimOliver/TOWebContentViewController/actions?query=workflow%3ACI)\n[![Version](https://img.shields.io/cocoapods/v/TOWebContentViewController.svg?style=flat)](http://cocoadocs.org/docsets/TOCropViewController)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/TimOliver/TOWebContentViewController/master/LICENSE)\n[![Platform](https://img.shields.io/cocoapods/p/TONavigationBar.svg?style=flat)](http://cocoadocs.org/docsets/TOWebContentViewController)\n[![PayPal](https://img.shields.io/badge/paypal-donate-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=M4RKULAVKV7K8)\n\n`TOWebContentViewController` is a class built to allow fast presentation of HTML, either from a local file or online. \n\nIt is not meant to be a web browser, but more to display specific information inside the app, where spending the resources to implement an equivalent native UI wouldn't be worth it. For example, displaying a privacy policy, or a list of open-source acknowledgements.\n\nThe view controller also features several extra niceties, such as being able to dynamically pre-set the background color, and using the [mustache](https://mustache.github.io/) templating system to dynamically inject information.\n\n## Features\n\n* Uses `WKWebView` to display HTML content and images, either from disk, or from a website.\n* Intentionally disallows 'back' or 'forward' navigation in favour of treating the content like a component of the app.\n* Tapping links is captured, and can be handled dynamically, or automatically by the view controller.\n* For local HTML content, allows the injection of dynamic information from the app (eg, app version, current year etc)\n* If present in the HTML, can extract the background color of the HTML content, and set the view controller view background to match while loading.\n\n## System Requirements\niOS 9.0 and above.\n\n## Installation\n\n**As a CocoaPods Dependency**\n\nAdd the following to your Podfile:\n```\npod 'TOWebContentViewController\n```\n\n**Manual Installation**\n\nCopy the folder `TOWebContentViewController` to your Xcode project.\n\n`TOWebContentViewController` is an Objective-C project, but it has been written to work properly in Swift as well. If you are using it in a Swift project, don't forget to include it in your Objective-C bridging header.\n\n## Examples\n\nFor on disk content, it is recommended you put all of your HTML/CSS in one folder and import it into Xcode as a 'Group Reference' (ie, so it uses a blue icon in the Xcode navigator) ([Screenshot](https://raw.githubusercontent.com/TimOliver/TOWebContentViewController/master/xcode-import.jpg))\n\n### Hello World Example\n\n```swift\n// Get resources folder URL\nlet resourcesURL = Bundle.main.resourceURL!\nlet baseURL = resourcesURL.appendingPathComponent(\"HTML\")\nlet fileURL = baseURL.appendingPathComponent(\"about.html\")\n\n// Create the web content view controller\nlet webContentController = WebContentViewController(fileURL: fileURL, baseURL: baseURL)\n\n// Present the view controller however way you need.\nnavigationController.push(webContentViewController, animated: true)\n```\n\n\n### Using the Templating System\n\nIf loading a local HTML file, a bare-bones mustache-based templating system has been implemented to allow the injection of dynamic content from your app into the HTML. This is useful for things like showing the current app version or build number, or even more clever things like swapping out CSS files.\n\nTo use the templating system, all you need to do is insert template tags into your HTML and then specify what they need to be replaced with.\n\n```swift\nlet myHTMLString = \"\u003chtml\u003e\u003cbody\u003e{{Greeting}}\u003c/body\u003e\u003c/html\u003e\"\n\nlet vc = WebContentViewController(htmlString: myHTMLString, baseURL: nil)\nvc.templateTags = [\"Greeting\": \"Hello World!\"]\n```\n\nWhen displayed, `{{Greeting}}` will be replaced with \"Hello World!\".\n\nYou can set your own custom values in `templateTags`, but the view controller also creates several by default:\n\n* `{{AppName}}` - The short name of the app from the main bundle (e.g. 'iComics')\n* `{{AppVersion}}` - The version number of this build of the app (e.g. '1.4')\n* `{{AppBuildNumber}}` - The build number of this version of the app (e.g. '1432')\n* `{{AppCurrentYear}}` - The current year according to the device (e.g. '2018')\n\n### Setting the Background Color\nBefore the web view has had a chance to load, you can dynamically set the background of the view controller to be the same color as the web content, so the appearance will look more native with the rest of the app.\n\nTo automatically set the color, place a tag named `data-bgcolor=\"\"` anywhere in your HTML file:\n\n```html\n\u003chtml\u003e\n\t\u003cbody data-bgcolor=\"#eeeeee\"\u003e\u003c/body\u003e\n\u003c/html\u003e\n```\n\nPlease note that you must use a 6 character hex code in order for this to work.\n\n## Credits\n`TOWebContentViewController` was originally created by [Tim Oliver](http://twitter.com/TimOliverAU) as a component for [iComics](http://icomics.co), a comic reader app for iOS.\n\niOS Device mockups used in the screenshot created by [Pixeden](http://www.pixeden.com).\n\n## License\nTOWebContentViewController is licensed under the MIT License, please see the [LICENSE](LICENSE) file. ![analytics](https://ga-beacon.appspot.com/UA-5643664-16/TOWebContentViewController/README.md?pixel)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimoliver%2Ftowebcontentviewcontroller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimoliver%2Ftowebcontentviewcontroller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimoliver%2Ftowebcontentviewcontroller/lists"}