This repository provides a declarative way to layout in SwiftUI-style. The DSL is based on KeyPath chaining so you can use any view property, don't need to create a DSL wrapper on your custom views, but you can create custom convinience modifiers.
view.add {
UIStackView.V {
UILabel("1")
.chain
.textAlignment(.center)
.textColor(.red)
.contentPriority(.required, axis: .horizontal, type: .compression)
UILabel().chain.text("2")
UIButton().chain.title("Button")
}
.alignment(.center)
.distribution(.equalSpacing)
.spacing(3)
.pin(.edges)
.pin(.width, 8)
.pin(aspectRatio: 1 / 2)
}
SubviewProtocol
- protocol describes any type that can be used as a subviewSubviewsBuilder
- function builder to create [SubviewProtocol]
, it allows use SwiftUI View
s as well (also you can use any SubviewProtocol
in SwiftUI ViewBuilder
)ViewComponent
- protocol describesLtView
, LtViewController
- helper classes with createLayout()
function to override, optional for use.chain
- property to create KeyPath
chaining for views, after .chain
you can write any property of view, then subscript with value ([value]
) or Publisher
to subscribe ([cb: somePublisher]
)do {...}
- function to any custom actions on viewadd {...}
- analog of addSubview
but with SubviewsBuilder
with {...}
- same as add
but returns the view itself, for using in layoutFor constraints this repo use pin
methods, examples:
UIView()
.pin(.edges)
.pin(to: .bottom, of: view2, options: .offset(4))
.pin(.bottom, 10..., to: view3)
.pin(.width, to: .height, of: superview, options: .multiplier(2), .offset(10))
Create a Package.swift
file.
// swift-tools-version:5.7
import PackageDescription
let package = Package(
name: "SomeProject",
dependencies: [
.package(url: "https://github.com/dankinsoid/VDLayout.git", from: "4.6.2")
],
targets: [
.target(name: "SomeProject", dependencies: ["VDLayout"])
]
)
$ swift build
dankinsoid, [email protected]
VDLayout is available under the MIT license. See the LICENSE file for more info.
link |
Stars: 6 |
Last commit: 4 days ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics