Dona

main

Declarative UIKit
timnazar/Dona

Doná

Doná (means seed in Tajik language) is a library based on Apple's UIKit which helps you to create your own declarative UI.

Usage Example

For more information use Wiki.

UImageView Example

private let imageView = UIImageView()
    .decorated(with: .namedImage("ExampleLogo"))
    .decorated(with: .contentMode(.scaleAspectFit))
    .decorated(with: .disabledAutoresizingMask())

UILabel Example

private let titleLabel = UILabel()
    .decorated(with: .text("Hello, World!"))
    .decorated(with: .textColor(.systemOrange))
    .decorated(with: .textAlignment(.center))
    .decorated(with: .font(.systemFont(ofSize: 16, weight: .medium)))
    .decorated(with: .disabledAutoresizingMask())

How to make your own custom ViewDecorator?

You can extened decorators with extension for ViewDecorator struct for implementing your own design system (learn what is design system). In example:

import DonaCore

extension DonaViewDecorator {
    static var largeTitle: DonaViewDecorator<UILabel> {
        DonaViewDecorator<UILabel> {
            $0.decorated(with: .disabledAutoresizingMask())
                .decorated(with: .font(.systemFont(ofSize: 29, weight: .bold)))
                .decorated(with: .textColor(.primary))
                .decorated(with: .numberOfLines(0))
        }
    }
}

After combining or creating new decorators you can use it as usual:

private let titleLabel = UILabel()
    .decorated(with: .text("Welcome 👋"))
    .decorated(with: .largeTitle)

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Apr 14 2024 15:49:04 GMT-0900 (Hawaii-Aleutian Daylight Time)