Q:

How to customize UIBarButtonItem with @IBDesignables?

@IBDesignable class AttributedBarButtonItem: UIBarButtonItem {

    @IBInspectable var fontSize: CGFloat = 22 {

        didSet {

            let attributes: [String: AnyObject] = [NSFontAttributeName: UIFont(name: "Icomoon", size: fontSize)!]
            setTitleTextAttributes(attributes, forState: .Normal)
        }
    }
}

This is how it looks like in Attributes inspector

But it doesnt change anything:

A:

@IBDesignable doesn't work with UIBarButtonItem, because @IBDesignable only works with UIView subclasses (on iOS), and UIBarButtonItem is not a UIView subclass.

A:

It can be customized ONLY via UINavigationBar:
@IBDesignable class AttributedNavigationBar: UINavigationBar {

    @IBInspectable var transparentBackground: Bool = false {

        didSet {

            setBackgroundImage(transparentBackground ? UIImage() : nil, forBarMetrics: .Default)
            shadowImage = transparentBackground ? UIImage() : nil
        }
    }

    @IBInspectable var fontSize: CGFloat = 18
    @IBInspectable var icomoonLeftBarButtonItems: Bool = false {

        didSet {

            let attributes = [NSFontAttributeName: UIFont(name: "Icomoon", size: fontSize)!]

            if let leftBarButtonItems = topItem?.leftBarButtonItems {

                for leftBarButtonItem in leftBarButtonItems {
                    leftBarButtonItem.setTitleTextAttributes(icomoonLeftBarButtonItems ? attributes : nil, forState: .Normal)
                }
            }
        }
    }
}

Works like a charm.

