Search code examples
iosswiftuibuttonstoryboardibdesignable

How can I fix this warning msg. Warning: Ignoring user defined runtime attribute for key path "radius" on instance of "UIButton"


I am getting this warning message. How can I fix this.

Warning: IB Designables: Ignoring user defined runtime attribute for key path radius on instance of UIButton. Hit an exception when attempting to set its value: [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key radius.

Here is custom UIButtonRounded class

@IBDesignable class UIButtonRounded: UIButton
{
    override func layoutSubviews() {
       super.layoutSubviews()
       updateCornerRadius()
    }

    @IBInspectable var rounded: Bool = false {
       didSet {
         updateCornerRadius()
       }
    }

    @IBInspectable var border: Bool = false {
       didSet {
        updateCornerRadius()
       }
    }

    @IBInspectable var radious: CGFloat = 0 {
       didSet {
        updateCornerRadius()
       }
    }

    func updateCornerRadius() {
       layer.cornerRadius = rounded ? radious : 0
       layer.masksToBounds = true
       if(border){
          layer.borderWidth = 1.3
          layer.borderColor = UIColor(named:"color_bg_white")?.cgColor
       }

    }
}

After Appling custom class

Custom class Attribute

Waring msg

Thanks In advance.


Solution

  • It's working for me:

    import UIKit
    
    @IBDesignable
    class DesignableView: UIView {
    }
    
    @IBDesignable
    class DesignableButton: UIButton {
    }
    
    @IBDesignable
    class DesignableLabel: UILabel {
    }
    
    extension UIView {
    
    @IBInspectable
    var cornerRadius: CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
        }
    }
    
    @IBInspectable
    var borderWidth: CGFloat {
        get {
            return layer.borderWidth
        }
        set {
            layer.borderWidth = newValue
        }
    }
    
    @IBInspectable
    var borderColor: UIColor? {
        get {
            if let color = layer.borderColor {
                return UIColor(cgColor: color)
            }
            return nil
        }
        set {
            if let color = newValue {
                layer.borderColor = color.cgColor
            } else {
                layer.borderColor = nil
            }
        }
    }
    
    @IBInspectable
    var shadowRadius: CGFloat {
        get {
            return layer.shadowRadius
        }
        set {
            layer.shadowRadius = newValue
        }
    }
    
    @IBInspectable
    var shadowOpacity: Float {
        get {
            return layer.shadowOpacity
        }
        set {
            layer.shadowOpacity = newValue
        }
    }
    
    @IBInspectable
    var shadowOffset: CGSize {
        get {
            return layer.shadowOffset
        }
        set {
            layer.shadowOffset = newValue
        }
    }
    
    @IBInspectable
    var shadowColor: UIColor? {
        get {
            if let color = layer.shadowColor {
                return UIColor(cgColor: color)
            }
            return nil
        }
        set {
            if let color = newValue {
                layer.shadowColor = color.cgColor
            } else {
                layer.shadowColor = nil
            }
         }
       }
    }