VDLayout is a lightweight and intuitive Swift library designed to simplify the layout building process in UIKit. By providing convenient extensions on native UIKit components, it allows developers to easily and quickly define user interfaces in a manner that is clean, efficient, and easy to understand. This library aims to offer a smooth integration into any UIKit project, and also SwiftUI, by avoiding complex abstractions or magic. It's essentially a friendly UIKit companion, making your layout code more readable and maintainable.
VDLayout introduces several key concepts:
content
property.With these elements, the library provides a simple, yet powerful toolkit for handling common layout tasks in UIKit.
The VDLayout library can be used to handle a variety of tasks.
For instance, you can easily chain together properties and methods on views:
public final class SomeView: UISubview {
private let label = UILabel()
override public var content: any Subview {
UIStackView.V(spacing: 3, alignment: .center) {
label
.chain
.textAlignment(.center)
.textColor(.red)
.contentPriority(.required, axis: .horizontal, type: .compression)
UILabel().chain
.text("Subtitle")
UIButton().chain
.title("Tap me")
}
.pin(.edges)
}
public func update(title: String) {
label.text = title
}
}
You can also use it to manage collections and tables:
let dataSource = UITableViewSource()
let tableView = UITableView(dataSource)
dataSource.reload(data: items) { _ in
SomeTableViewCell()
} reload: { cell, item in
cell.text = item.name
}
VDLayout extends various UIKit components with numerous useful methods. For a full list, see here.
VDLayout is available via Swift Package Manager (SPM).
To install it, simply add the following line to the dependencies value of your Package.swift:
dependencies: [
.package(url: "https://github.com/dankinsoid/VDLayout.git", from: "4.12.1")
]
Then, in your target dependencies, add "VDLayout"
:
targets: [
.target(
name: "YourTarget",
dependencies: ["VDLayout"]),
]
VDLayout makes use of several related libraries:
For any queries or suggestions, feel free to open an issue on GitHub.
This document was co-authored by an OpenAI language model. The descriptions and examples have been reviewed for accuracy and clarity. If you have any corrections or improvements, please open an issue or make a pull request on GitHub.
link |
Stars: 7 |
Last commit: 1 week ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics