UIKitSwiftDSL
Swift DSL for UIKit. Simple DSL in Swift which gives you opportunity to write layout code in readable and declarative way.
Usage
let rootView = stack {
$0.spacing = 16
$0.axis = .vertical
$0.isLayoutMarginsRelativeArrangement = true
$0.stack {
$0.distribution = .fillEqually
$0.axis = .horizontal
$0.label {
$0.textAlignment = .center
$0.textColor = .white
$0.text = "Hello"
}
$0.label {
$0.textAlignment = .center
$0.textColor = .white
$0.text = "World"
}
$0.customLabel {
$0.textAlignment = .center
$0.textColor = .white
$0.text = "!!!"
}
}
let messageButton = $0.button {
$0.tintColor = .white
$0.setTitle("Say Hi!", for: .normal)
}
$0.view {
$0.backgroundColor = .clear
}
}
Custom View
If you are using some Custom Views in your project you can easily add it to support DSL.
import UIKitSwiftDSL
class CustomLabel: UILabel {
// Custom implementation here
}
extension UIView {
@discardableResult
func customLabel(apply closure: (CustomLabel) -> Void) -> CustomLabel {
return custom(CustomLabel(), apply: closure)
}
}
AutoLayout
UIKitSwiftDSL doesn't have any logic related to AutoLayout. You can use any library you want.
$0.button {
$0.tintColor = .white
$0.setTitle("Say Hi!", for: .normal)
// Add your AutoLayout code here.
}
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Installation
UIKitSwiftDSL is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'UIKitSwiftDSL'
UIKitSwiftDSL is available through Carthage. To install it, simply add the following line to your Cartfile:
github "mecid/UIKitSwiftDSL"
Author
Majid Jabrayilov, [email protected]
License
UIKitSwiftDSL is available under the MIT license. See the LICENSE file for more info.