https://github.com/fuzza/outfit
Composable outfit for your UIKit elements
https://github.com/fuzza/outfit
functional styles swift uikit
Last synced: 3 months ago
JSON representation
Composable outfit for your UIKit elements
- Host: GitHub
- URL: https://github.com/fuzza/outfit
- Owner: fuzza
- License: mit
- Created: 2019-01-26T13:44:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-16T18:39:59.000Z (over 4 years ago)
- Last Synced: 2025-06-28T04:38:56.628Z (4 months ago)
- Topics: functional, styles, swift, uikit
- Language: Swift
- Size: 17.6 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Outfit
[](https://travis-ci.org/fuzza/Outfit)
[](https://cocoapods.org/pods/Outfit)
[](https://cocoapods.org/pods/Outfit)
[](https://cocoapods.org/pods/Outfit)* [Usage](#Usage)
* [Basic usage](#Basicusage)
* [Advanced usage](#Advancedusage)
* [Outfit composition](#Outfitcomposition)
* [Reuse outfits in subclasses](#Reuseoutfitsinsubclasses)
* [Override default properties](#Overridedefaultproperties)
* [Example](#Example)
* [Requirements](#Requirements)
* [Installation](#Installation)
* [Author](#Author)
* [License](#License)1. Import the framework
```swift
import Outfit
```2. Define conformance of your class to `Outfitable` protocol
```swift
extension MyCustomView: Outfitable {}
```
3. Extend your wardrobe with some nice outfit
```swift
extension Wardrobe where Wearer: MyCustomView {
func perfectLook() -> Outfit {
return {
// Customize the instance of MyCustomView
$0.titleColor = .red
$0.placeholder = "It's something new"
$0.clipsToBounds = true
}
}
}```
4. Access your wardrobe and try it on
```swift
let view = MyCustomView()
view.wrd.tryOn {
$0.perfectLook()
}
```5. Have fun!
You can combine outfits together using custom concat operator (++)
```swift
extension Wardrobe where Wearer: UIView {
func rounded(_ radius: CGFloat) -> Outfit {
return {
$0.layer.masksToBounds = true
$0.layer.cornerRadius = radius
}
}
func background(_ color: UIColor) -> Outfit {
return { $0.backgroundColor = color }
}func defaultView() -> Outfit {
return rounded(5.0)
++ background(.white)
}
}
```#### Reuse outfits in subclasses
You can reuse outfits from parent class in the child
```swift
extension Wardrobe where Wearer: UIView {
func defaultView() -> Outfit { ... }
}extension Wardrobe where Wearer: UIButton {
func title(_ text: String) -> Outfit {
return {
$0.setTitle(text, for: .normal)
}
}func defaultButton() -> Outfit {
return defaultView()
++ title("Default title")
}
}```
#### Override default properties
If you need to override some property in a single place or add new one, and it doesn't make a sense to define new function for this:
```swift
func viewDidLoad() {
super.viewDidLoad()let view = MyCustomView()
view.wrd.tryOn {
$0.perfectLook()
++ { $0.titleColor = .green }
}
}
```To run the example project, clone the repo, and run `pod install` from the Example directory first.
* Swift 4.2
* Xcode 10Outfit is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'Outfit'
```Oleksii Faizullov, alex.fuzza@gmail.com
Outfit is available under the MIT license. See the LICENSE file for more info.