Skip to content

Instantly share code, notes, and snippets.

@kurtroberts
Created February 27, 2024 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtroberts/7cadbd06c5f7ad0fd5c659f01c1c4963 to your computer and use it in GitHub Desktop.
Save kurtroberts/7cadbd06c5f7ad0fd5c659f01c1c4963 to your computer and use it in GitHub Desktop.
Using a SwiftUI layout inside a UIKit View Controller
//
// ExampleSwiftUIView.swift
// Example
//
// Created by Kurt Roberts on 2/26/24.
//
import SwiftUI
struct ExampleSwiftUIView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Knock, knock!")
}
.padding()
}
}
//
// ExampleViewController.swift
// Example
//
// Created by Kurt Roberts on 2/27/24.
//
import UIKit
import SwiftUI
final class ExampleViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let vc = UIHostingController(rootView: ExampleSwiftUIView())
present(vc, animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment