iOS WebView All In One
阅读原文时间:2023年07月09日阅读:1

iOS WebView All In One

WKWebView / UIWebView

//: 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()

https://developer.apple.com/documentation/uikit/uiwebview

class UIWebView : UIView

https://developer.apple.com/documentation/webkit/wkwebview

// iOS, Mac Catalyst

class WKWebView : UIView


// macOS
class WKWebView : NSView

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html#//apple_ref/doc/uid/TP40011210

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html

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

https://github.com/paulirish/iOS-WebView-App



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器