我曾尝试将addSubview
SwiftUI 视图转换为 UIView。self.view.addSubview(contentView)
错误:无法将“ContentView”类型的值转换为预期的参数类型“UIView”
请帮我实现这个用户界面。
import UIKit
import SwiftUI
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = UIColor.lightGray
let contentView = ContentView()
view.addSubview(contentView) // Error: Cannot convert value of type 'ContentView' to expected argument type 'UIView'
}
}
struct ContentView: View {
var body: some View {
Text("Hello world")
}
}