CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

Freestyler 1.0.0

Freestyler 1.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2016
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Alexander Doloz, Alexander Doloz.



  • By
  • Alexander Doloz

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: swift label <~ UILabel.style(textColor: UIColor.red)
  • Save style to some variable: swift let redTextColor = UILabel.style(textColor: UIColor.red)
  • Apply style above to multiple labels: swift [label1, label2] <~ redTextColor
  • Style which makes text color green and bold font: swift 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: swift 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: swift 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

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.