Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@IBDesignable UIButton Extension

Tags:

ios

swift

I am trying to extend the UIButton class by adding a cornerRadius property which can be changed at the design time without having to build the app. I am using the following extension class:

import UIKit

@IBDesignable
extension UIButton {

    @IBInspectable var cornerRadius :CGFloat {

        get {
            return layer.cornerRadius
        }

        set {

            layer.cornerRadius = newValue
            layer.masksToBounds = newValue > 0
        }
    }

}

But when I make a change of the property cornerRadius in the Storyboard I do not see the change happening live! Am I missing something!

like image 661
john doe Avatar asked Sep 08 '15 23:09

john doe


1 Answers

Extensions don't honor the IBDesignable qualifier. Only actual subclasses do. Annoying but true.

like image 79
Duncan C Avatar answered Oct 19 '22 19:10

Duncan C