StyleSheet
StyleSheet copied to clipboard
Reusable and composable UI styles
StyleSheet
An approach to define reusable and composable UI styles.
Having some base styles defined you can use them like so:
final class TitleLabel: UILabel, TitleFontStyle {}
final class BodyLabel: UILabel, BodyFontStyle, MultilineLabelStyle {}
final class CaptionLabel: UILabel, CaptionFontStyle, MultilineLabelStyle {}
For a complete usage example see the Example project.
For the implementation details see Style.swift
and RootStyle.swift
.
Motivation
Why to define the UI style in code?
Defining the UI style in code is good because it gives
- reproducible,
- reusable,
- and composable results.
Why not to use UIAppearance?
Because we can do better. By avoiding the use of the appearance-proxy we can access all properties and methods (not only UI_APPEARANCE_SELECTOR
and dynamic
), and nested objects!
Supported base classes
Base class | UIAppearance | StyleSheet | Notes |
---|---|---|---|
NSView | ✓ | ||
UIView | ✓ | ✓ | |
UIBarItem | ✓ | ✗ | See the issue #1 |
Installation
Carthage
github "werediver/StyleSheet" ~> 5.0
CacoaPods
pod 'StyleSheet', :git => 'https://github.com/werediver/StyleSheet.git', :tag => 'v5.0.0'
Note: check the latest available version!