EasyStyle 是一个 Swift 函数式框架,允许您通过 使用 Swift 函数的可组合、类型安全的 UIView 样式化 和 使用函数的 UIKit 样式化 来程序化地创建 UI 样式。
易于使用
下面是一个示例,虽然很简单,但它展示了如何组合样式
结果 | 代码 |
---|---|
特性
- 轻量级且易于使用
- 样式组合
- 自动完成支持
- 代码简洁易读
安装
EasyStyle 通过 CocoaPods 提供。要安装它,只需在您的 podfile 中添加以下行
pod "EasyStyle"
而对于 Carthage 用户,只需将 Mantle 添加到您的 Cartfile 中
github "0ber/EasyStyle"
使用方法
首先为 UILabel 创建一个样式
// MARK: Label Style
extension LabelStyle {
private static let h1 = font(.systemFont(ofSize: 28))
private static let title = h1 + textColor(.red)) + aligment(.center)
static let easyStyle = title + text("Easy Style")
}
然后 just set style to label
let titleLabel = UILabel()
titleLabel.setStyle(.easyStyle) // set style
作者
Alex Kalinkin - @KalinkinAleksey
许可
EasyStyle 适用于 MIT 许可。有关更多信息,请参阅 LICENSE 文件。