测试测试过 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2016年12月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Alexander Doloz, Alexander Doloz 维护。
Freestyler 允许你使用声明性语法在单个位置定义应用的样式,这样你可以轻松地在整个应用中更改颜色、字体和其他视觉属性。
swift label <~ UILabel.style(textColor: UIColor.red)
swift let redTextColor = UILabel.style(textColor: UIColor.red)
swift [label1, label2] <~ redTextColor
swift let greenTextColorAndBoldFont <~ UILabel.style(textColor: UIColor.green) <~ UILabel.style(font: UIFont.boldSystemFont(ofSize: 14.0)) /// 或 let greenTextColorAndBoldFont <~ [UILabel.style(textColor: UIColor.green), UILabel.style(font: UIFont.boldSystemFont(ofSize: 14.0))] /// 或 let greenTextColorAndBoldFont: Style = [UILabel.style(textColor: UIColor.green), UILabel.style(font: UIFont.boldSystemFont(ofSize: 14.0))]
swift label <~ [redTextColor, greenTextColorAndBoldFont] // ^ 标签将是绿色且加粗 label <~ [greenTextColorAndBoldFont, redTextColor] // ^ 标签将是红色;尽管如此,它仍然是加粗的
UIView
的样式应用到 UILabel
,但不能反过来;通常,你可以将类的样式应用到子类的实例:swift label <~ UIView.style(backgroundColor: UIColor.yellow) // 下面的代码将崩溃 🔥 view <~ UILabel.style(textColor: UIColor.red)
使用协议 Color
,你可以为应用中经常遇到的颜色创建调色板并给予有意义的名字。它还将帮助你有一个所有颜色都集中存放的地方,这样你可以用一行代码改变整个应用中的颜色。
enum Theme: Color {
case title
case subtitle
case background
var color: UIColor {
switch self {
case .title: return UIColor.black
case .subtitle: return UIColor.lightGray
case .background: return UIColor.white
}
}
}
// ... somewhere in code
label <~ UILabel.style(textColor: Theme.title)
同样,字体也有类似的 Font
协议。
enum Typography: Font {
case big
case medium
case small
var font: Font {
switch self {
case .big: return UIFont.systemFont(ofSize: 18.0)
case .medium: return UIFont.systemFont(ofSize: 14.0)
case .small: return UIFont.systemFont(ofSize: 11.0)
}
}
}
// ... somewhere in code
label <~ UILabel.style(font: Typography.big)
Freestyler
文件夹拖到 Xcode 的项目中;请确保 亚历山大·多洛兹,[email protected]
Freestyler 在 MIT 许可下可用。更多详细信息请参阅 LICENSE.txt 文件。