Ans :
IBDesignable and IBInspectable , a way to create custom elements and the attributes . This can be directly added to the iOS Interface Builder.
IBDesignable :
IBDesignable attribute will identify the UIView or the elements inherited from UIView
i.e: UIButton, UIImageView, UILabel etc
Code :
@IBDesignable
open class KGHighLightedButton: UIButton {
}
IBInspectable :
@IBInspectable var borderWidth: Double {
get {
return Double(self.layer.borderWidth)
}
set {
self.layer.borderWidth = CGFloat(newValue)
}
}
@IBInspectable var borderColor: UIColor? {
get {
return UIColor(cgColor: self.layer.borderColor!)
}
set {
self.layer.borderColor = newValue?.cgColor
}
}
Due to above code, you can set above properties in attribute inspector like following :
So using @IBDesignable and @IBInspectable, you can change make inspectable property and see live changes in IB interface builder without run.
Note :
IBInspectable can be used with the below types,
Int
CGFloat
Double
String
Bool
CGPoint
CGSize
CGRect
UIColor
UIImage
IBDesignable and IBInspectable , a way to create custom elements and the attributes . This can be directly added to the iOS Interface Builder.
IBDesignable :
IBDesignable attribute will identify the UIView or the elements inherited from UIView
i.e: UIButton, UIImageView, UILabel etc
Code :
@IBDesignable
open class KGHighLightedButton: UIButton {
}
IBInspectable :
@IBInspectable var borderWidth: Double {
get {
return Double(self.layer.borderWidth)
}
set {
self.layer.borderWidth = CGFloat(newValue)
}
}
@IBInspectable var borderColor: UIColor? {
get {
return UIColor(cgColor: self.layer.borderColor!)
}
set {
self.layer.borderColor = newValue?.cgColor
}
}
Due to above code, you can set above properties in attribute inspector like following :
So using @IBDesignable and @IBInspectable, you can change make inspectable property and see live changes in IB interface builder without run.
Note :
IBInspectable can be used with the below types,
Int
CGFloat
Double
String
Bool
CGPoint
CGSize
CGRect
UIColor
UIImage
No comments:
Post a Comment
Thanks