Latest 0.1.0
Homepage https://github.com/fuzza/Outfit
License MIT
Platforms ios 9.0
Authors

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.

Latest podspec

{
    "name": "Outfit",
    "version": "0.1.0",
    "summary": "Composable outfit for your UIKit elements",
    "description": "Easy UIKit elements styling using functional composition.",
    "homepage": "https://github.com/fuzza/Outfit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "fuzza": "[email protected]"
    },
    "source": {
        "git": "https://github.com/fuzza/Outfit.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "9.0"
    },
    "swift_version": "4.2",
    "default_subspecs": "All",
    "subspecs": [
        {
            "name": "All",
            "dependencies": {
                "Outfit/Core": [],
                "Outfit/UI": []
            }
        },
        {
            "name": "Core",
            "source_files": "Outfit/Core/**/*"
        },
        {
            "name": "UI",
            "source_files": "Outfit/UIKit/**/*",
            "frameworks": "UIKit",
            "dependencies": {
                "Outfit/Core": []
            }
        }
    ]
}

Pin It on Pinterest

Share This