iOS WebView All In One
iOS WebView All In One
WKWebView / UIWebView
Swift Playground
//: A UIKit based Playground for presenting user interface
import PlaygroundSupport
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string:"https://www.apple.com")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = ViewController()
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
let label = UILabel()
label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
label.text = "Hello World!"
label.textColor = .black
view.addSubview(label)
self.view = view
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
UIWebView 👎 已废弃
https://developer.apple.com/documentation/uikit/uiwebview
class UIWebView : UIView
WKWebView 👍
https://developer.apple.com/documentation/webkit/wkwebview
// iOS, Mac Catalyst
class WKWebView : UIView
// macOS
class WKWebView : NSView
Objective-C
Objective-C 代码的文件扩展名
扩展名 内容类型
.h 头文件。头文件包含类,类型,函数和常数的声明。
.m 源代码文件。这是典型的源代码文件扩展名,可以包含 Objective-C 和 C 代码。
.mm 源代码文件。带有这种扩展名的源代码文件,除了可以包含Objective-C和C代码以外还可以包含C++代码。仅在你的Objective-C代码中确实需要使用C++类或者特性的时候才用这种扩展名。
https://www.runoob.com/w3cnote/objective-c-tutorial.html
https://www.runoob.com/ios/ios-objective-c.html
refs
https://github.com/paulirish/iOS-WebView-App
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13883680.html
未经授权禁止转载,违者必究!