Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- //
- // Collection of styles
- //
- private var styles:Dictionary<String,((view:UIView) -> Void)> = Dictionary()
- class StyleCollection {
- class func addStyle(style:String, paint:((view:UIView) -> Void)) -> Void {
- styles[style] = paint
- }
- class func applyStyle(style:String?, view:UIView) -> Void {
- // if no style defined
- if (style == nil) {
- return
- }
- // let's apply!
- let styleList = style!.characters.split{$0 == " "}.map(String.init)
- for style:String in styleList {
- applyStyle(style, view:view)
- }
- }
- private class func applyStyle(style:String, view:UIView) -> Void {
- if let paint = styles[style] {
- paint(view:view)
- }
- }
- }
- //
- // Adds style property to UIView so styles can be applied
- //
- extension UIView {
- @IBInspectable var style: String! {
- get {
- return nil
- }
- set(newValue) {
- StyleCollection.applyStyle(newValue, view:self)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement