【发布时间】:2022-01-24 14:06:55
【问题描述】:
我正在尝试显示 5 个 Web 视图,并且我希望在 for 循环中创建 Web 视图。我目前使用的代码只创建一个 web 视图,它应该为页面中的每个 url 创建一个。任何帮助将不胜感激!
import UIKit
import Foundation
import WebKit
import AVFoundation
class displayviews: UIViewController, WKUIDelegate {
var pages = ["https://example.com", "https://example", "https://example", "https://example.com", "https://example.com"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
for i in pages{
var inti = Int(i) ?? 0
//var currentwebview = String("webView") + i
let myWebView:WKWebView = WKWebView(frame: CGRect(x:0, y:CGFloat(inti*200), width: UIScreen.main.bounds.width, height:UIScreen.main.bounds.height/CGFloat(pages.count)))
myWebView.uiDelegate = self
self.view.addSubview(myWebView)
//1. Load web site into my web view
let myURL = URL(string: pages[inti])
let myURLRequest:URLRequest = URLRequest(url: myURL!)
myWebView.load(myURLRequest)
}
}
}
【问题讨论】:
标签: swift web view wkwebview wkwebviewconfiguration