4

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.

Farwa
  • 6,156
  • 8
  • 31
  • 46
Rafiqul Hasan
  • 3,324
  • 4
  • 20
  • 28
  • Possible duplicate of [UIButton with IB\_DESIGNABLE throws runtime attribute warning and does not render in Interface Builder](https://stackoverflow.com/questions/26656400/uibutton-with-ib-designable-throws-runtime-attribute-warning-and-does-not-render) – gmogames Mar 20 '18 at 06:44
  • Already tried. Did not work for me. – Rafiqul Hasan Mar 20 '18 at 06:53

2 Answers2

1

If you make a value and change it later it will still exists in the user defined runtime attributes in the Identity Inspector. Go there and delete the old value.

Jevon Charles
  • 644
  • 1
  • 7
  • 12
-1

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
        }
     }
   }
}
Jamil Hasnine Tamim
  • 4,389
  • 27
  • 43