XCTLViewController.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // UIViewController.swift
  3. // notebook
  4. //
  5. // Created by 邢铖 on 2023/5/18.
  6. //
  7. import UIKit
  8. public class XCTLViewController: UIViewController, XCTLGenerateProtocol {
  9. public static func initWithXCT(_ arg: [Any]) throws -> NSObject {
  10. let obj = XCTLViewController()
  11. for it in arg {
  12. if let vc = it as? UIViewController {
  13. obj.addChild(vc)
  14. } else {
  15. throw XCTLRuntimeError.generateProtocolArgumentError(needs: "VC...")
  16. }
  17. }
  18. return obj
  19. }
  20. public override func viewDidLoad() {
  21. self.view.backgroundColor = UIColor.systemCyan
  22. super.viewDidLoad()
  23. for it in self.children {
  24. self.view.addSubview(it.view)
  25. }
  26. for (id, it) in view.subviews.enumerated() {
  27. it.translatesAutoresizingMaskIntoConstraints = false
  28. if id == 0 {
  29. it.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
  30. } else {
  31. it.heightAnchor.constraint(equalTo: self.view.subviews[id - 1].heightAnchor).isActive = true
  32. }
  33. it.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
  34. it.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
  35. if id == view.subviews.count - 1 {
  36. it.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
  37. }
  38. }
  39. }
  40. }