SwiftUIのようなシンタックスのAutoLayoutライブラリを作りかけた。

Updated
Sep 19, 2019 2:00 PM
Created
Sep 18, 2019 8:30 AM
Tags
SwiftUIKit
Keywords
Date

final class MyView: BoxContainerView {
  
  let toggleView = UISwitch()
  var flag: Bool = false
  
  private let top = UIView.make(backgroundColor: .red)
  private let section = UIView.make(backgroundColor: .orange)
  private let name = UILabel.make(text: "@Muukii")
  private let bg = UIView.make(backgroundColor: .blue)
  private let age = UILabel.make(text: "28")
  
  override func boxLayoutThatFits() -> BoxType {
    BoxCenter {      
      BoxVStack {
        BoxElement { toggleView }
        BoxEmpty()
          .frame(height: 20)
        if flag {
          BoxElement { top }
            .aspectRatio(ratio: CGSize(width: 1, height: 1))
        }
        BoxElement { section }
          .aspectRatio(ratio: CGSize(width: 1, height: 0.2))
        BoxZStack {
          BoxElement { bg }
          BoxHStack {
            BoxElement { name }
            BoxHSpacer()
            BoxElement { age }
          }
        }
        }
        .frame(width: 200, height: nil)
    }
  }
}

image
image