oscarimonbox
8/8/2018 - 11:32 AM

Añadir propiedad a una extension

//SACADO DE AQUI: https://stackoverflow.com/a/25428013


private var xoAssociationKey: CGFloat = 0
extension UIButton {

    var originalFontSize : CGFloat? {
        get {
            return objc_getAssociatedObject(self, &xoAssociationKey) as? CGFloat
        }
        set(newValue) {
            objc_setAssociatedObject(self, &xoAssociationKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
        }
    }
    
    open override func awakeFromNib() {
        
        let currentFont = self.titleLabel?.font;
        if self.originalFontSize == nil {
            self.originalFontSize = currentFont?.pointSize
        }
        let fontSize = Utils.getFontSize(originalFontSize: (self.originalFontSize)!);
        
        self.titleLabel?.font = currentFont?.withSize(fontSize);
        
    }

}