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

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

refs

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



©xgqfrms 2012-2020

www.cnblogs.com 發布文章使用:只允許注冊用戶才可以訪問!



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM