Created
April 19, 2020 00:19
-
-
Save azamsharp/1dcc2f1895849e47d74833d6983bd24a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// DemoHostingC | |
// | |
// Created by Mohammad Azam on 4/18/20. | |
// Copyright © 2020 Mohammad Azam. All rights reserved. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) | |
.background(Color.green) | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// DemoHostingC | |
// | |
// Created by Mohammad Azam on 4/18/20. | |
// Copyright © 2020 Mohammad Azam. All rights reserved. | |
// | |
import UIKit | |
import SwiftUI | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
let controller = UIHostingController(rootView: ContentView()) | |
controller.view.translatesAutoresizingMaskIntoConstraints = false | |
self.addChild(controller) | |
self.view.addSubview(controller.view) | |
controller.didMove(toParent: self) | |
NSLayoutConstraint.activate([ | |
controller.view.widthAnchor.constraint(equalToConstant: 200), | |
controller.view.heightAnchor.constraint(equalToConstant: 44), | |
controller.view.centerXAnchor.constraint(equalTo: self.view.centerXAnchor), | |
controller.view.centerYAnchor.constraint(equalTo: self.view.centerYAnchor) | |
]) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment