Latest 1.1.1
Homepage https://github.com/takecian/ComposableStyling
License MIT
Platforms ios 10.0
Authors

ComposableStyling provides sets of functions for styling views and composable operators.

Composable operator

<> operator composes same signature functions.

precedencegroup SingleTypeComposition {
    associativity: left
}

infix operator<>: SingleTypeComposition

public func <> <A: AnyObject>(f: @escaping (A) -> Void, g: @escaping (A) -> Void) -> (A) -> Void {
    return { a in
        f(a)
        g(a)
    }
}

Installation

pod 'ComposableStyling'

Usage

1. Create styling function by composing styling functions you want to apply.

e.g. In case that we want to,

  • set background color red
  • set boarder color blue and 10 to width

We can create styling function by composing 2 functions.

let style = styleViewBackgroundColor(.red) <>
            styleViewBorder(color: .blue, width: 10)
  1. Apply styling function to view.
let view = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 100))
style(view)

Comaparison

ComposableStyling helps us understand what design applied.

Before

let view = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 100))
view.backgroundColor = .red
view.layer.cornerRadius = 30
view.layer.masksToBounds = true
view.layer.borderWidth = 10
view.layer.borderColor = .blue

After

let view = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 100))

let style = styleViewBackgroundColor(.red) <>
            styleViewCornerRadius(30) <>
            styleViewBorder(color: .blue, width: 10)

style(view)

Latest podspec

{
    "name": "ComposableStyling",
    "version": "1.1.1",
    "summary": "Functional styling in Swift.",
    "description": "Functional styling provides elegant composable styling implementation in Swift.",
    "homepage": "https://github.com/takecian/ComposableStyling",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "takecian": "[email protected]"
    },
    "source": {
        "git": "https://github.com/takecian/ComposableStyling.git",
        "tag": "1.1.1"
    },
    "swift_version": "4.2",
    "platforms": {
        "ios": "10.0"
    },
    "source_files": "ComposableStyling/*.swift"
}

Pin It on Pinterest

Share This