TWKit 可通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中:
pod 'TWKit'
或
pod 'TWKit/EasyStyle'
pod 'TWKit/GetConstraint'
pod 'TWKit/AttributedString'
pod 'TWKit/KeyboardHelper'
pod 'TWKit/ObjectPool'
pod 'TWKit/StructObject'
pod 'TWKit/Extension'
pod 'TWKit/Function'
为了仅对视图应用设计而避免使用 IBOutlet 将代码与视图连接,轻松地将视图应用于样式而开发 'MGEStyles' 为 swift,并同时允许应用多个样式。
let manger = EasyStyleManager.sharedInstance
manger.registerStyle("sample") { view in
if let label = view as? UILabel {
label.backgroundColor = UIColor.blueColor()
}
}
manger.registerStyle("test") { view in
if let label = view as? UILabel {
label.textColor = UIColor.cyanColor()
}
}
使用界面构建器很棒,因为不需要使用 IBOutlet:
view.easyStyle = "test, sample"
不喜欢视图和代码通过 IBOutlet 连接并且有许多变量被引用,因此开发 Left,Right 和 Leading,Trailing 的不同之处,并注意使用。
let topConstraint = view.getConstraint(attribute: .Top)
topConstraint?.constant = 20
为了轻松地将样式应用于 NSAttributedString 开发
let text = "Label {sample} test message {icon} sample message {icon} Label"
let attributeString: NSAttributedString = text.toAttributedString([
"Lab": [NSForegroundColorAttributeName : UIColor.brownColor()],
"a": [NSBackgroundColorAttributeName : UIColor.purpleColor()],
"{sample}": [TWKitUIImageAttributeName: UIImage(named: "sample")!],
"{icon}": [TWKitUIImageAttributeName: UIImage(named: "icon")!]
])
label.attributedText = attributeString
//添加到结果屏幕截图
当 scrollTop 中存在 TextField 时,可以轻松地应用 contentInset。
let keyboardHelper = KeyboardHelper(scrollview)
//添加到结果屏幕截图
为了简化对象的再利用而开发
let objPool = ObjectPool<UILabel> {
return UILabel()
}
//객체 생성
for i in 0..<10 {
let label = objPool.getInstance()
}
//사용이 끝나면 objPool로 되돌려준다.
for label in objPool.activeList {
objPool.returnInstance(label)
}
当想将 struct 放入 sender: AnyObject 中时使用!
let stObj = StructObject(CGRectMake(0,0,10,10))
let rect = StructObject<CGRect>.from(stObj)
print("StructObject as CGRect is: \(rect)")
在数组使用中简单地将 Arrays 用于可选。
let arr = ["test","sample"]
arr[2] //Error
arr[safe: 2] //nil
taewankim, [email protected]
MIT
受项目启发