Lilith 是一个用 Swift 编写的 UI 库,旨在使使用 UIKit 更快、更友好。
Lilith 处于早期 alpha 版本,正在积极开发中。更多信息和完善文档即将推出。
Lilith 通过 CocoaPods 提供使用。要安装它,只需将以下行添加到您的 Podfile
pod "Lilith"
全面文档可在 Cocoadocs 上找到!
LFConfigurations 是可以应用于 Lilith 的基于文本类的外观属性的集合。
let config = LFConfiguration(font: UIFont(name: "Avenir Next", size: 20)!, textColor: .blackColor(), textAlignment: .Center, numberOfLines: 0, resize: true)
创建 `LFConfiguration` 后,您可以使用它来配置像 `LFLabel` 这样的类。这允许您避免重复输入大量的代码。
//A label made with Lilith
let frame = CGRect(x: 16, y: 32, width: view.frame.width-32, height: 64)
let label = LFLabel(frame: frame, configuration: config, text: "Hello world!")
view.addSubview(label)
以下是使用默认 UIKit 时的相同标签的外观。看看它是多么的代码!
//Original label made with UIKit
let frame = CGRect(x: 16, y: 0, width: view.frame.width-32, height: 64)
let label = UILabel(frame: frame)
label.text = "Hello world!"
label.font = UIFont(named:"Avenir Next", size:20)
label.textColor = .BlackColor
label.textAlignment = .Left
label.numberOfLines = 0
label.sizeToFit()
view.addSubview(label)
请记住,LFConfigurations 可以用于所有基于文本的类,例如 LFButton。可以将从配置中应用到上述 LFLabel 中的相同属性直接应用于 LFButton,而无需重新输入相同的代码。哦,我应该提到 Lilith 有自定义初始化器来帮助您加快编码速度。
//Create a LFButton with the full width of the view at a certain point and adjust the height automatically
let button = LFButton(text: "Click me", view: view, point: 0, configuration: config)
button.below(label2, padding: 16) //Move's the button below a certain view with optional padding
button.target("doSomething", object: self) //Quickly Target a method (assumes the control event is TouchUpInside)
view.addSubview(button)
Lilith 的基于文本的类内置了众多不同的功能,全部都是为了简化您的 UI 代码!
// Sets the text color. For LFButtons it automatically lightens or darkens the color for the highlighted state
textColor(textColor: UIColor)
// Sets the font size of the current font
fontSize(size: CGFloat)
// Moves the object below a certain view with optional padding. (A fast replacement for CGRectGetMaxY)
below(view: UIView, padding: CGFloat)
// Moves the object above a certain view with optional padding. (A fast replacement for CGRectGetMinY)
above(view: UIView, padding: CGFloat)
// These functions will adjust the alignment of the text. Even for the LFButton.
leftText()
centerText()
rightText()
//Sets the number of lines for a label.
lines(lines: Int)
// Automatically adjusts the height of the object to fit it's text while maintaining the width.
resize()
// For LFButtons only. Sets the title for both the normal and highlighted state.
setText(text: String)
// Resets the objects entire configuration with a new one.
setConfiguration(configuration: LFConfiguration)
// For buttons only. Adds a target for the touch up inside event.
target(action: String, object: AnyObject)
要运行示例项目,首先克隆仓库,然后从 Example 目录运行 pod install
。
Josh Arnold, [email protected]
Lilith 适用于 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。