https://github.com/werediver/stylesheet
Reusable and composable UI styles
https://github.com/werediver/stylesheet
ios macos stylesheet swift uiappearance uikit
Last synced: 12 months ago
JSON representation
Reusable and composable UI styles
- Host: GitHub
- URL: https://github.com/werediver/stylesheet
- Owner: werediver
- License: mit
- Created: 2016-10-20T14:39:19.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-09-29T12:12:18.000Z (over 7 years ago)
- Last Synced: 2025-06-05T02:34:16.070Z (about 1 year ago)
- Topics: ios, macos, stylesheet, swift, uiappearance, uikit
- Language: Swift
- Homepage:
- Size: 252 KB
- Stars: 23
- Watchers: 4
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://swift.org/)

[](https://github.com/Carthage/Carthage)
[](https://cocoapods.org/)
# StyleSheet
An approach to define reusable and composable UI styles.
Having some base styles defined you can use them like so:
```swift
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](Example/) project.
For the implementation details see [`Style.swift`](Sources/Style.swift) and [`RootStyle.swift`](Sources/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](https://github.com/werediver/StyleSheet/issues/1) |
## Installation
### Carthage
```
github "werediver/StyleSheet" ~> 5.0
```
### CacoaPods
```ruby
pod 'StyleSheet', :git => 'https://github.com/werediver/StyleSheet.git', :tag => 'v5.0.0'
```
Note: check the latest available version!
## License
[MIT](https://github.com/werediver/StyleSheet/blob/master/LICENSE)