TWKit 0.0.8

TWKit 0.0.8

测试已测试
语言语言 SwiftSwift
许可 MIT
发布最后发布2016年9月
SPM支持 SPM

taewan0530 维护。



TWKit 0.0.8

  • 作者
  • taewan

TWKit

安装

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'

EasyStyle

为了仅对视图应用设计而避免使用 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()
    }
}

应用样式

通过 Interface Builder

使用界面构建器很棒,因为不需要使用 IBOutlet:

通过代码

view.easyStyle = "test, sample"

结果

获取约束

不喜欢视图和代码通过 IBOutlet 连接并且有许多变量被引用,因此开发 Left,Right 和 Leading,Trailing 的不同之处,并注意使用。

let topConstraint = view.getConstraint(attribute: .Top)
topConstraint?.constant = 20

AttributedString

为了轻松地将样式应用于 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

//添加到结果屏幕截图

KeyboardHelper

当 scrollTop 中存在 TextField 时,可以轻松地应用 contentInset。

let keyboardHelper = KeyboardHelper(scrollview)

//添加到结果屏幕截图

ObjectPool

为了简化对象的再利用而开发

let objPool = ObjectPool<UILabel> {
    return UILabel()
}

//객체 생성
for i in 0..<10 {
    let label = objPool.getInstance()    
}

//사용이 끝나면 objPool로 되돌려준다.
for label in objPool.activeList {
    objPool.returnInstance(label)
}

StructObject

当想将 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

参考资料

受项目启发