Latest 1.0.0
Homepage https://github.com/cayugasoft/Freestyler
License MIT
Platforms ios 8.0
Dependencies FreestylerCore
Authors

Freestyler
Freestyler
Freestyler
Freestyler

What is it?

Freestyler lets you define styles for your application in a single place using declarative syntax, so you can easily change colors, fonts and other visual properties across all the app.

How to use it?

  • Make label text color red:

    label <~ UILabel.style(textColor: UIColor.red)
  • Save style to some variable:

    let redTextColor = UILabel.style(textColor: UIColor.red)
  • Apply style above to multiple labels:

    [label1, label2] <~ redTextColor
  • Style which makes text color green and bold font:

    let greenTextColorAndBoldFont <~ UILabel.style(textColor: UIColor.green) <~ UILabel.style(font: UIFont.boldSystemFont(ofSize: 14.0))
    /// or 
    let greenTextColorAndBoldFont <~ [UILabel.style(textColor: UIColor.green), UILabel.style(font: UIFont.boldSystemFont(ofSize: 14.0))]
    /// or
    let greenTextColorAndBoldFont: Style = [UILabel.style(textColor: UIColor.green), UILabel.style(font: UIFont.boldSystemFont(ofSize: 14.0))]
  • Application of styles is not commutative, i.e. order matters:

    label <~ [redTextColor, greenTextColorAndBoldFont] 
    // ^ label will be green and bold
    label <~ [greenTextColorAndBoldFont, redTextColor]
    // ^ label will be red; also bold though
  • You can apply style of UIView to UILabel but not vice versa; in general, you can apply style of class to instance of subclass:

    label <~ UIView.style(backgroundColor: UIColor.yellow)
    // code below will crash 🔥
    view <~ UILabel.style(textColor: UIColor.red)
  • Using protocol Color, you can create palettes for often encountered colors in your app and give them meaningful name. It will also help to have a central place where all colors located so you can change them across all the app with one line of code:

    enum Theme: Color {
        case title
        case subtitle
        case background
    
        var color: UIColor {
            switch self {
            case .title: return UIColor.black
            case .subtitle: return UIColor.lightGray
            case .background: return UIColor.white
            }
        }
    }
    
    // ... somewhere in code
    
    label <~ UILabel.style(textColor: Theme.title)
  • Also the same thing for fonts – Font protocol:

    enum Typography: Font {
        case big
        case medium
        case small
    
        var font: Font {
            switch self {
            case .big: return UIFont.systemFont(ofSize: 18.0)
            case .medium: return UIFont.systemFont(ofSize: 14.0)
            case .small: return UIFont.systemFont(ofSize: 11.0)
            }
        }
    }
    
    // ... somewhere in code
    
    label <~ UILabel.style(font: Typography.big)

Requirements

  • iOS 8.0+
  • Swift 3
  • Xcode 8.0+

Installation

Cocoapods

  1. Install Cocoapods: sudo gem install cocoapods
  2. Create Podfile in your project directory.
  3. Add in your Podfile:

    use_frameworks!
    pod 'Freestyler', '~> 1.0'
  4. Run pod install
  5. import Freestyler in your .swift files.

Carthage

Carthage is currently not supported.

Manually

  1. Clone or download Freestyler
  2. Drag Freestyler folder to your project in Xcode; make sure ☑️ Copy items into destination’s group folder (if needed) option is checked.

Author

Alexander Doloz, [email protected]

License

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

Latest podspec

{
    "name": "Freestyler",
    "version": "1.0.0",
    "license": {
        "type": "MIT",
        "file": "LICENSE.txt"
    },
    "homepage": "https://github.com/cayugasoft/Freestyler",
    "authors": {
        "Alexander Doloz": "[email protected]"
    },
    "summary": "Swift 3 framework for styling + big set of styles for builtin UIView subclasses",
    "description": "Freestyler provides styles and protocols so you can perform theming of your application with ease.",
    "source": {
        "git": "https://github.com/cayugasoft/Freestyler.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Freestyler/**/*.swift",
    "ios": {
        "frameworks": "UIKit"
    },
    "dependencies": {
        "FreestylerCore": [
            "~> 1.0.1"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This