XCTLViewController.swift 1.5 KB

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