C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Outlet: An outlet is a field in our Swift file. It is a way for our Swift code to reference a control from the Main.storyboard.
PageHtml: This is a constant that contains some HTML text. It has a background of "aliceblue," my favorite color.
LoadHTMLString: This method is an instance method on our UIWebView. We call this on the field added in the "add outlet" step.
FuncExample UIWebView code: Swift
//
// ViewController.swift
// ExampleTimeD
//
// ...
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var simpleWeb: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// somexampleHTML
let pageHtml = "<html><p style=background:aliceblue>"
+ "<b>Hello friend,</b> " +
"how are you?</p></html>";
// Use loadHTMLString to display content.
// ... Use nil for baseURL.
simpleWeb.loadHTMLString(pageHtml,
baseURL: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Result: The HTML string is rendered in the Web View. The HTML paragraph is only one line, so we only see a single line of aliceblue color.