Skip to content
/ Miel Public

Define constraints in elegant, declarative way as it should be in 2024

Notifications You must be signed in to change notification settings

aKozlovv/Miel

Repository files navigation

Miel

Nothing but sugar for UIKit autolayout

Frame 1

Miel provides more elegant and declarative approach for build layout. Thanks to the power of the builder pattern this package provides more control over every constraint.

Example:

 Layout {
            label.layout
                .top
                .equal(to: view.layout.top)
                .constant(50)
            
            label.layout
                .width
                .equal(to: view.bounds.size.width / 2)
            
            button.layout
                .top
                .equal(to: label.layout.bottom)
                .constant(15)
            
            button.layout
                .leading
                .equal(to: view.layout.leading)
                .constant(15)
            
            button.layout
                .trailing
                .equal(to: view.layout.trailing)
                .constant(-15)
        }

Features

  • Global result builder
  • Ready to use
  • More control over every anchor

Usage

Just install package via Swift Package Manager and you will able to call "buildLayout" method. The method returns a prototype for customization. All the usual properties such as top, leading, height and so on are available for constraint customization

button.buildLayout { prototype in
            prototype
                .height
                .equal(to: 50)
            
            prototype
                .width
                .equal(to: 130)
        }

This library has been designed for more elegant use. The library provides a Layout structure that allows you to describe constraints for any View within a closure. Example:

Layout {
            label.layout
                .top
                .equal(to: view.layout.top)
                .constant(50)
            
            label.layout
                .width
                .equal(to: view.bounds.size.width / 2)
            
            button.layout
                .top
                .equal(to: label.layout.bottom)
                .constant(15)
            
            button.layout
                .leading
                .equal(to: view.layout.leading)
                .constant(15)
            
            button.layout
                .trailing
                .equal(to: view.layout.trailing)
                .constant(-15)
        }

About

Define constraints in elegant, declarative way as it should be in 2024

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages