测试已测试 | ✗ |
兰语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2016年11月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Alexander Doloz 维护。
当我们从设计师的草图中开发应用程序时,我们经常一遍又一遍地遇到相同的视觉模式 - 颜色、字体等。将它们保存在应用程序代码的一个地方并在每个地方重用是一个明智的决定。这正是 FreestylerCore 助您做到的。
FreestylerCore定义了一个名为 Style
的类别。可以将多个 Style
合并成一个。参见用法部分了解如何创建您自己的样式并应用它们。
FreestylerCore是更大框架的一部分 - Freestyler。 Freestyler = FreestylerCore + 大量样式。目前它正在积极开发中,欢迎贡献力量。
Source
文件夹拖动到 Xcode 中的项目;确保已选中这里是基本用法,更多示例请参见 Playground。
let roundCorners = Style("Round corners") {
(view: UIView) in
view.layer.cornerRadius = 5.0
}
let redBorder = Style("Red Border") {
(view: UIView) in
view.layer.borderColor = UIColor.red.CGColor
}
button <~ roundCorners <~ redBorder
// --- or ---
button <~ [roundCorners, redBorder]
// You can combine multiple styles into one
let style = roundCorners <~ redBorder
button <~ style
// You can apply style to multiple items at once
[button, label, imageView] <~ style
// And multiple styles to multiple labels too
[button, label, imageView] <~ [roundCorners, redBorder]
如果您不喜欢使用自定义运算符,有相应的方法
button.apply(style: roundCorners).apply(style: redBorder)
// --- or ---
button.apply(styles: [roundCorners, redBorder])
// You can instantiate style from array literal
let style: Style = [roundCorners, redBorder]
button.apply(style: style)
// You can apply style to multiple items at once
[button, label, imageView].apply(style: style)
// And multiple styles to multiple labels too
[button, label, imageView].apply(styles: [roundCorners, redBorder])
Alexander Doloz,[email protected]
FreestylerCore 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE.txt 文件。