Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mecid/uikitswiftdsl
Swift DSL for UIKit
https://github.com/mecid/uikitswiftdsl
dsl ios ios-swift swift uikit
Last synced: about 1 month ago
JSON representation
Swift DSL for UIKit
- Host: GitHub
- URL: https://github.com/mecid/uikitswiftdsl
- Owner: mecid
- License: mit
- Created: 2019-01-20T09:48:34.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-08T20:09:32.000Z (over 5 years ago)
- Last Synced: 2024-09-18T15:40:55.119Z (about 2 months ago)
- Topics: dsl, ios, ios-swift, swift, uikit
- Language: Swift
- Size: 35.2 KB
- Stars: 154
- Watchers: 6
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UIKitSwiftDSL
[![Version](https://img.shields.io/cocoapods/v/UIKitSwiftDSL.svg?style=flat)](https://cocoapods.org/pods/UIKitSwiftDSL)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![License](https://img.shields.io/cocoapods/l/UIKitSwiftDSL.svg?style=flat)](https://cocoapods.org/pods/UIKitSwiftDSL)
[![Platform](https://img.shields.io/cocoapods/p/UIKitSwiftDSL.svg?style=flat)](https://cocoapods.org/pods/UIKitSwiftDSL)Swift DSL for UIKit. Simple DSL in Swift which gives you opportunity to write layout code in readable and declarative way.
## Usage
```swift
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.```swift
import UIKitSwiftDSLclass 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.```swift
$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](https://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'UIKitSwiftDSL'
```UIKitSwiftDSL is available through [Carthage](https://github.com/Carthage/Carthage). To install
it, simply add the following line to your Cartfile:```ruby
github "mecid/UIKitSwiftDSL"
```## Author
Majid Jabrayilov, [email protected]
## License
UIKitSwiftDSL is available under the MIT license. See the LICENSE file for more info.