CoreUI

一个以声明式和函数式风格构建用户界面的库。构建于 UIKit 之上,并支持旧版本的 iOS。

import UIKit
import CoreUI

class MyViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    addSubview(
      UI.VScrollView(
        contentInset: .vertical(12),
        UI.VStack(
          UI.View(backgroundColor: .red, height: 20),
          UI.Label("Are you sure?", font: .systemFont(ofSize: 24), color: .label),
          UI.Spacer(minHeight: 30),
          UI.HStack(
            spacing: 12,
            UI.Button("Yes").apply { $0.addTarget(self, action: #selector(yesTapped), for: .touchUpInside) },
            UI.Button("No").apply { $0.addTarget(self, action: #selector(noTapped), for: .touchUpInside) }
          )
        ),
        .leading(6), .trailing(-6), .safeTop(0), .safeBottom(0)
      )
    )
  }

}