UIBuilder
[](https://travis-ci.org/Eric Chapman/UIBuilder)
示例
要运行示例项目,请克隆存储库,然后首先从 Example 目录中运行 pod install
。
安装
UIBuilder 可通过 CocoaPods 获取。要安装它,请只需将以下行添加到 Podfile 即可。
pod 'UIBuilder'
用法
以下是一个使用此库的示例。请参阅wiki上的文档。
请注意,我还没有编写单元测试。目前运行的示例只是为了确保所有方法都能正常工作。
import UIKit
import UIBuilder
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.gray
let stripeHeight: CGFloat = 20
// Build the top side
let blueSquare = UIView()
blueSquare.backgroundColor = UIColor.blue
let blueSquareElement = blueSquare.element.height(7*stripeHeight).width(7*stripeHeight).halign(.left).valign(.top)
var tStripes = [UIBuilderElement]()
for i in 0..<7 {
let stripe = UIView()
stripe.backgroundColor = (i % 2) == 0 ? UIColor.red : UIColor.white
tStripes.append(stripe.element.height(stripeHeight))
}
let topRightStripes = UIBuilder.stack(vertical: tStripes)
let topHStack = UIBuilder.stack(horizontal: [blueSquareElement, topRightStripes])
// Build the bottom side
var bStripes = [UIBuilderElement]()
for i in 0..<7 {
let stripe = UIView()
stripe.backgroundColor = (i % 2) == 0 ? UIColor.white : UIColor.red
bStripes.append(stripe.element.height(stripeHeight))
}
let bottomVStack = UIBuilder.stack(vertical: bStripes)
// Combine the top and bottom
let mainView = UIBuilder.stack(vertical: [topHStack, bottomVStack]).build()
self.view.addSubview(mainView)
self.view.constrain.leftEdges(mainView).build()
self.view.constrain.rightEdges(mainView).build()
self.view.constrain.topEdges(mainView).build()
}
}
许可证
UIBuilder遵循MIT许可证。有关更多信息,请参阅LICENSE文件。