项目作者: thedoritos

项目描述 :
Build UI for iOS application by code
高级语言: Swift
项目地址: git://github.com/thedoritos/suugar.git
创建时间: 2019-03-17T08:25:11Z
项目社区:https://github.com/thedoritos/suugar

开源协议:MIT License

下载


Suugar

Suugar (pronounced as sugar) is an experimental project to build UI for iOS application by code of Swift.

Concepts

Readable Hierarchy

Suugar allows you to write UI hierarchy with nested calls of methods.

  1. ui {
  2. $0.stack {
  3. $0.image {
  4. $0.image = UIImage(named: "ic_hello")
  5. }
  6. $0.label {
  7. $0.text = "Hello, Suugar!!"
  8. }
  9. }
  10. }

Regular UIKit Components

All of nests are just regular method calls, and each $0 is standard UIKit component.
So, you can write code with UIKit just like you do usually.

  1. ui {
  2. // $0 is UIView
  3. $0.backgroundColor = UIColor.white
  4. $0.table {
  5. // $0 is UITableView
  6. $0.estimatedRowHeight = UITableView.automaticDimension
  7. $0.register(HelloTableViewCell.self, forCellReuseIdentifier: "cell")
  8. $0.dataSource = self
  9. }
  10. }

Easily Reusable Views

If you have custom views already using, you can easily integrate it into the hierarchy.

  1. class HelloView: UIStackView {
  2. // TODO: Override init methods to call render
  3. private func render() {
  4. ui {
  5. $0.image {
  6. $0.image = UIImage(named: "ic_hello")
  7. }
  8. $0.label {
  9. $0.text = "Hello, Again!!"
  10. }
  11. }
  12. }
  13. }
  1. ui {
  2. // By specifying the type
  3. $0.composite(HelloView.self)
  4. // Or ask compiler to do it
  5. let view: HelloView = $0.composite()
  6. }