Проверка шаблона шины для iOS
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

addSwiftUIAsChild.swift 689B

il y a 1 an
12345678910111213141516171819
  1. import SwiftUI
  2. @discardableResult
  3. public func addSwiftUIViewAsChild<Type>(
  4. swiftUIView: Type,
  5. parent: UIView
  6. ) -> UIHostingController<Type> {
  7. let childVC = UIHostingController(rootView: swiftUIView)
  8. childVC.view.backgroundColor = .clear
  9. parent.addSubview(childVC.view)
  10. childVC.view.translatesAutoresizingMaskIntoConstraints = false
  11. NSLayoutConstraint.activate([
  12. childVC.view.topAnchor.constraint(equalTo: parent.topAnchor),
  13. childVC.view.bottomAnchor.constraint(equalTo: parent.bottomAnchor),
  14. childVC.view.leadingAnchor.constraint(equalTo: parent.leadingAnchor),
  15. childVC.view.trailingAnchor.constraint(equalTo: parent.trailingAnchor),
  16. ])
  17. return childVC
  18. }