DnpKit 是一个辅助工具,旨在提高您在 iOS 上编码的效率。
要求
- iOS 10.0+
- Xcode 10.0+
- Swift 5.0+
如果平台 iOS < 10.0,则安装 DnpKit 3.7.0 和 SnapKit 4.2,Swift 4.2
安装
CocoaPods
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target '<Your Target Name>' do
pod 'DnpKit'
end
运行以下命令
$ pod install
用法
快速开始
UILabel
import DnpKit
class ViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
UILabel().dnp
.text("Text")
.textColor(UIColor.black)
.font(15)
.numberOfLines(1)
.addToSuperView(self.view)
.makeSnapKit { (make) in
make.left.top.equalToSuperview()
}
.object
}
}
UIButton
class ViewController: UIViewController{
override func viewDidLoad() {
UIButton(type: .custom).dnp
.title("Button", .normal)
.image(UIImage(named: "Image")!, .normal)
.titleFont(14)
.tintColor(UIColor.gray)
.addToSuperView(self.view)
.makeSnapKit({ (make) in
make.width.height.equalTo(40)
make.top.left.equalToSuperview()
})
.addTarget(self, #selector(buttonClick(sender:)), .touchUpInside)
.object
}
}
UITableView
class ViewController: UIViewController{
lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain).dnp
.dataSource(self)
.delegate(self)
//.contentInsetAdjustmentBehavior(.never)
.adJustedContentIOS11()
.estimatedRowHeight(70)
.estimatedSectionFooterHeight(0)
.estimatedSectionHeaderHeight(0)
.showsVerticalScrollIndicator(false)
.separatorStyle(.singleLine)
.backgroundColor(UIColor.cyan)
.backgroundView(UIView())
.addToSuperView(self.view)
.register(TableViewCell.self, forCellReuseIdentifier: "TableViewCell")
.object
return tableView
}()
}
UIView
class ViewController: UIViewController{
override func viewDidLoad() {
UIView().dnp
.frame(15, 88, UIScreen.main.bounds.width, 60)
.backgroundColor(UIColor.cyan)
.cornerRadius(10)
.addSubView(self.view)
.addGesture(UIGestureRecognizer())
.makeSnapKit { (make) in
make.edges.equalToSuperview()
}
}
}
创建代码片段
- UILable: nl
private lazy var <#label#>Lb: UILabel = {
return UILabel().dnp
.text(<#""#>).font(<#17#>)
.textColor(UIColor.<#red#>)
.textAlignment(.<#left#>)
.addToSuperView(<#self.contentView#>)
.object
}()