Swiftpack.co - dankinsoid/VDLayout as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by dankinsoid.
dankinsoid/VDLayout 4.11.0
Declarative wrapper on UIKit
⭐️ 7
🕓 34 weeks ago
iOS
.package(url: "https://github.com/dankinsoid/VDLayout.git", from: "4.11.0")

VDLayout

Version License Platform

Table of Contents

Overview

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.

Concepts

VDLayout introduces several key concepts:

  • Subview and SubviewBuilder: These types allow for the creation and configuration of subviews within a parent view.
  • UISubview and UISubviewController: These are helper subclasses for UIView and UIViewController respectively. You can inherit these to override the content property.
  • Chain: This is a view wrapper that enables method chaining on a view via keypaths.
  • pin(_:) methods: These methods allow for the creation of auto-layout constraints.
  • UIKitView: This is a SwiftUI wrapper around UIView and UIViewController that supports chaining and provides seamless integration of UIKit components with SwiftUI.
  • CellsSection and ViewCell: These structures are used for building and managing cells in table and collection views.
  • ViewCellsReloadable: This is a protocol that marks a view as having reloadable cells.

With these elements, the library provides a simple, yet powerful toolkit for handling common layout tasks in UIKit.

Usage and Examples

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
}

List of Methods and Extensions

VDLayout extends various UIKit components with numerous useful methods. For a full list, see here.

Installation

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.11.0")
]

Then, in your target dependencies, add "VDLayout":

targets: [
    .target(
        name: "YourTarget",
        dependencies: ["VDLayout"]),
]

Related Libraries

VDLayout makes use of several related libraries:

  • VDPin: A Swift library for easy creation of AutoLayout constraints.
  • VDChain: A Swift library that enables method chaining on views via keypaths.
  • UIKitViews: A Swift library providing seamless integration of UIKit components with the SwiftUI framework

Contributors

  • Voidilov Daniil: Main Developer
  • OpenAI's ChatGPT: Contributor to README

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.

GitHub

link
Stars: 7
Last commit: 34 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics