Swible
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
- 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
}
}
- Design your view and add
@IBInspectable
properties. - Sometimes Xcode/Interface Builder does not recognize
Designable
subclasses as@IBDesignable
. !Workaround! Declare your custom class as@IBDesignable
like:
@IBDesignable
class CustomView: DesignableView {
}
Author
- e-Sixt, [email protected]
Contributors:
- Franz Busch, [email protected]
License
Swible is available under the MIT license. See the LICENSE file for more info.