Проверка шаблона шины для iOS
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

addSwiftUIAsChild.swift 689B

11 个月前
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. }