Last active
July 4, 2021 12:32
-
-
Save laevandus/5befb110792e88e56ffd17b0b0dbd65e to your computer and use it in GitHub Desktop.
This file contains 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
import UIKit | |
import SwiftUI | |
final class ContentViewController: UIViewController { | |
override func loadView() { | |
self.view = UIView() | |
self.view.backgroundColor = .systemBackground | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let stackView = UIStackView(frame: .zero) | |
stackView.translatesAutoresizingMaskIntoConstraints = false | |
view.addSubview(stackView) | |
NSLayoutConstraint.activate([ | |
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16), | |
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16), | |
stackView.topAnchor.constraint(equalTo: view.topAnchor, constant: 16) | |
]) | |
let label = UILabel(frame: .zero) | |
label.translatesAutoresizingMaskIntoConstraints = false | |
stackView.addArrangedSubview(label) | |
label.textColor = .systemRed | |
label.text = "Red text" | |
} | |
} | |
// MARK: SwiftUI Preview | |
#if DEBUG | |
struct ContentViewControllerContainerView: UIViewControllerRepresentable { | |
typealias UIViewControllerType = ContentViewController | |
func makeUIViewController(context: Context) -> UIViewControllerType { | |
return ContentViewController() | |
} | |
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {} | |
} | |
struct ContentViewController_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentViewControllerContainerView().colorScheme(.light) // or .dark | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment