Skip to content
/ Outfit Public

Composable outfit for your UIKit elements

License

Notifications You must be signed in to change notification settings

fuzza/Outfit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Outfit

CI Status Version License Platform

Usage

Basic usage

  1. Import the framework
import Outfit
  1. Define conformance of your class to Outfitable protocol
extension MyCustomView: Outfitable {}
  1. Extend your wardrobe with some nice outfit
extension Wardrobe where Wearer: MyCustomView {

    func perfectLook() -> Outfit<Wearer> {
        return { 
            // Customize the instance of MyCustomView
            $0.titleColor = .red
            $0.placeholder = "It's something new"
            $0.clipsToBounds = true
        }
    }
}
  1. Access your wardrobe and try it on
let view = MyCustomView()

view.wrd.tryOn { 
    $0.perfectLook() 
}
  1. Have fun!

Advanced usage

Outfit composition

You can combine outfits together using custom concat operator (++)

extension Wardrobe where Wearer: UIView {
    func rounded(_ radius: CGFloat) -> Outfit<Wearer> {
        return {
            $0.layer.masksToBounds = true
            $0.layer.cornerRadius = radius
        }
    }
  
    func background(_ color: UIColor) -> Outfit<Wearer> {
        return { $0.backgroundColor = color }
    }

    func defaultView() -> Outfit<Wearer> {
        return rounded(5.0)
        ++ background(.white)
    }
}

Reuse outfits in subclasses

You can reuse outfits from parent class in the child

extension Wardrobe where Wearer: UIView {
    func defaultView() -> Outfit<Wearer> { ... }
}

extension Wardrobe where Wearer: UIButton {
    func title(_ text: String) -> Outfit<Wearer> {
        return {
            $0.setTitle(text, for: .normal)
        }
    }

    func defaultButton() -> Outfit<Wearer> {
        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:

func viewDidLoad() {
    super.viewDidLoad()

    let view = MyCustomView()
    view.wrd.tryOn {
        $0.perfectLook()
        ++ { $0.titleColor = .green }
    }
}

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Swift 4.2
  • Xcode 10

Installation

Outfit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Outfit'

Author

Oleksii Faizullov, [email protected]

License

Outfit is available under the MIT license. See the LICENSE file for more info.

About

Composable outfit for your UIKit elements

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published