FreestylerCore 1.0.1

FreestylerCore 1.0.1

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

Maintained by Alexander Doloz.



  • By
  • Alexander Doloz

What is it?

When we develop our applications from designer's mockups, we often encounter the same visual patterns over and over again – colors, fonts, etc. It's wise decision to keep them in one place in your app's code and reuse everywhere. That's exactly what FreestylerCore helps you to do.

FreestylerCore defines class Style. Style can be applied to UIView or UIBarButtonItem. Multiple Styles can be combined into one. See how to create your own styles and apply them in Usage section.

FreestylerCore is meant to be the part of the bigger framework – Freestyler. Freestyler = FreestylerCore + big bunch of styles. It's currently in active development and contributions are welcome.

Requirements

  • iOS 8.0+
  • Swift 3
  • Xcode 8.0+

Installation

Manually

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

Usage

Here is basic usage; see more examples in Playground.

  • Create style:
let roundCorners = Style("Round corners") {
    (view: UIView) in
    view.layer.cornerRadius = 5.0
}
let redBorder = Style("Red Border") {
    (view: UIView) in
    view.layer.borderColor = UIColor.red.CGColor
}
  • Apply style:
button <~ roundCorners <~ redBorder
// --- or ---
button <~ [roundCorners, redBorder]

// You can combine multiple styles into one 
let style = roundCorners <~ redBorder
button <~ style

// You can apply style to multiple items at once
[button, label, imageView] <~ style

// And multiple styles to multiple labels too
[button, label, imageView] <~ [roundCorners, redBorder]

If you don't like using custom operators, there are corresponding methods:

button.apply(style: roundCorners).apply(style: redBorder)
// --- or ---
button.apply(styles: [roundCorners, redBorder])

// You can instantiate style from array literal
let style: Style = [roundCorners, redBorder]
button.apply(style: style)

// You can apply style to multiple items at once
[button, label, imageView].apply(style: style)

// And multiple styles to multiple labels too
[button, label, imageView].apply(styles: [roundCorners, redBorder])

Goals

  • Add unit tests to all operators and methods.
  • Add support for other platforms, especially for macOS.
  • Add support for Swift Package Manager.

Author

Alexander Doloz, [email protected]

License

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