How to use IBDesignable in Swift 3.0
Step 1 : Create a class DesignableView Parents of UIView. Adding prefix of
How To @IBInspectable In Swift.
@IBDesignable
class DesignableView: UIView {
// Corner Radius.
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
}
}
//Background Color.
@IBInspectable var backColor: UIColor? {
didSet {
backgroundColor = backColor
}
}
//Border Width.
@IBInspectable var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth
}
}
//Border Color.
@IBInspectable var borderColor: UIColor? {
didSet {
layer.borderColor = borderColor?.cgColor
}
}
}
Step 2 : In the StoryBoard you take the UIView and given the class name DesignableView which is you define already define programmatically. See below image.
Step 3 : Whenever you give the parents class as DesignableView then its defined properties are display in the property inspection. now user can easily change the define value from the property inspection. and the view also render according to value. see below image.
Step 4 : After set of the all property, you can see the view of behavior in stotyboard before the run. now run the app you get the result.
Step 3 : Whenever you give the parents class as DesignableView then its defined properties are display in the property inspection. now user can easily change the define value from the property inspection. and the view also render according to value. see below image.
Step 4 : After set of the all property, you can see the view of behavior in stotyboard before the run. now run the app you get the result.
How to use IBDesignable in Swift 3.0
Reviewed by KIRIT MODI
on
08:12:00
Rating:
No comments: