Monday, May 9, 2016

Open Web Page in iOS

Showing a web page in your iOS app is a two step process. Maybe even a one step process if you already have a web view setup.
// 1. Setup the web view
let webView: WKWebView = WKWebView()
view.addSubview(webView)
webView.frame = view.frame

// 2. Setup the request
let url = NSURL(string: "http://swiftquickstart.blogspot.com/")!
let request = NSURLRequest(URL: url)
webView.loadRequest(request)
Recommendations:
  • The webView variable should be global in your view controller
  • Set the webView.frame in viewDidLayoutSubviews so when you change orientation it gets reset

(Swift 2.2)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

SwiftUI Search & Filter with Combine - Part 3 (iOS, Xcode 13, SwiftUI, 2...

In part 3 of the Searchable video series, I show you how to use Combine in #SwiftUI for the search and filter logic connected to the searcha...