Swible

Swible - Designables made easy in Swift


Keywords
cocoapod, ibdesignable, ios, storyboard, swift
License
MIT
Install
pod try Swible

Documentation

Swible

Build Status codecov Badge w/ Version GitHub license

Getting Started

Swible is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Swible"

Usage

Swible core protocol is Designable which requires to methods to be implemented.

public protocol Designable: class {
    func setup()
    func applyStyling()
}

Setup: Is the first point where you can design your view. Main focus here should be to do the setup of code which only happen once. Often times you add subviews and constrain them inside this method.

Apply Styling: Should be used to customize the appearance of your views, for example you would set the backgroundColor, font or aligment here. It is called after setup and can be called multiple times.

UIKit subclasses

Swible provides a couple of base classes for UIKit views. To create your own designable view, choose a subclass which fits your element and subclass from it. Here is an example for a custom UIView

  1. Create a new DesingableView (or any other Designable___) subclass like
class CustomView: DesignableView {

    override func setup() {
        // Do any setup in here, e.g. creating constraints in code
    }

    override func applyStyling() {
        // Do any styling in here, e.g. background color
    }

}
  1. Design your view and add @IBInspectable properties.
  2. Sometimes Xcode/Interface Builder does not recognize Designable subclasses as @IBDesignable. !Workaround! Declare your custom class as @IBDesignable like:
@IBDesignable
class CustomView: DesignableView {
}

Author

Contributors:

License

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

alt text