NimbleKit 2.1

NimbleKit 2.1

Zafirzzf 维护。



  • 作者:
  • zhouzf

NImbleKit

用 Swift 快速设置视图,告别 "="。

更灵活,更方便

CocoaPods

pod 'NimbleKit'

设置一个按钮

之前

let editButton = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
editButton.setTitle("编辑", for: .normal)
editButton.setTitle("完成", for: .selected)
editButton.setTitleColor(UIColor.red, for: .normal)
editButton.setTitleColor(UIColor.brown, for: .selected)
editButton.backgroundColor = UIColor.red
editButton.layer.cornerRadius = 10
....

之后

let editButton = UIButton().nb
	.frameRect(0, 0, 50, 50)
	.title("编辑")
	.title("完成", state: .selected)
	.titleColor(UIColor.red)
	.titleColor(UIColor.brown, state: .selected)
	.backgroundColor(UIColor.red)
	.cornerRadius(10).base
	....

不需要更多的赋值操作。

创建成员标签

之前

class ViewController: UIViewController {

/// property
var label: UILabel = {
    let tmp = UILabel()
    tmp.textColor = .white
    tmp.text = "aaa"
    ...
    return tmp
}()

override func viewDidLoad() {
}

之后

class ViewController: UIViewController {

let label = UILabel().nb.textColor(.white).text("aaa").base

override func viewDidLoad() {
}

调整视图位置

有时你需要这样做

let view = UIView()
view.frame.size.width = 100
view.frame.size.height = 100
view.center.x = 150
view.center.y = 150

现在,适用于任何UIView

view.nb.width(100).height(100).centerX(150).centerY(150).base