A declarative alternative to SwiftUI which uses UIKit
Installation
Swift Package Manager (SPM)
To install Styleable using Swift Package Manager you can follow the tutorial published by Apple using the URL for the Styleable repo with the current version:
Styleable adds some sugar to the good old UIKit that makes it look and feel almost as SwiftUI. This does not intend to be a replacement for SwiftUI, instead it inteds to help making the transition smoother and with less risks along the way.
Getting started
Styleable uses the power of UIStackViews and the convenience of @resultBuilders to allow building the UI structure in a human readable fashion.
Core components of Styleable
VStackView
A subclass of UIStackView that has the axis locked to .vertical and allows the use of result builders for arrangedSubviews
HStackView
A subclass of UIStackView that has the axis locked to .horizontall and allows the use of result builders for arrangedSubviews
ZStackView
A subclass of UIView that lays out views one on top of the other. Useful when a container view is needed or when we need to pin subviews with some padding.
Styles
A Style encapsulates some customization that can be reused / applied to any object of the target type. This way you can define some styles and apply them whenever needed.
Observation: You can apply as many styles as you want to a view. The styles are applied in the same order they are passed. So if you want to make sure the customization of a style are visible, move it to the end of the list.
Observation: You can also apply styles of an ancestor class to any custom view.
Styleable
A declarative alternative to SwiftUI which uses UIKit
Installation
Swift Package Manager (SPM)
To install Styleable using Swift Package Manager you can follow the tutorial published by Apple using the URL for the Styleable repo with the current version:
In Xcode, select “File” → “Swift Packages” → “Add Package Dependency”
Enter https://github.com/radu-costea/Styleable.git
Introduction
Styleable adds some sugar to the good old UIKit that makes it look and feel almost as SwiftUI. This does not intend to be a replacement for SwiftUI, instead it inteds to help making the transition smoother and with less risks along the way.
Getting started
Styleable uses the power of UIStackViews and the convenience of
@resultBuilders
to allow building the UI structure in a human readable fashion.Core components of Styleable
VStackView
A subclass of UIStackView that has the axis locked to
.vertical
and allows the use of result builders forarrangedSubviews
HStackView
A subclass of UIStackView that has the axis locked to
.horizontall
and allows the use of result builders forarrangedSubviews
ZStackView
A subclass of UIView that lays out views one on top of the other. Useful when a container view is needed or when we need to pin subviews with some padding.
Styles
A Style encapsulates some customization that can be reused / applied to any object of the target type. This way you can define some styles and apply them whenever needed. Observation: You can apply as many styles as you want to a view. The styles are applied in the same order they are passed. So if you want to make sure the customization of a style are visible, move it to the end of the list.
Observation: You can also apply styles of an ancestor class to any custom view.
Examples:
A login form
With styles:
The new login form:
More examples coming soon..