How to use the @IBDesignable and @IBInspectable?
By giving you a simple example that we can not change the corner radius from the design view. We have to change it run time. If you want to make possible it with design time then you can use the @IBDesignable and @IBInspectable.
So, We are taking an example as IBButtonExtender for this the functionality
- Border Color
- Border Width
- Corner Radius
Create an Custom Class for UIButton with @IBDesignable
1 2 3 |
@IBDesignable class ButtonExtender: UIButton { } |
Create an @IBInspectable for Inspect the element. the Border Color property will be added to the list in the right panel when you create button with this class.
1 2 3 4 5 |
@IBInspectable var borderColor: UIColor = UIColor.white { didSet { layer.borderColor = borderColor.cgColor } } |
Set Initialization functions and other @IBInspectable as above.
You can check the code for the ButtonExtender.swift
IBButtonExtender
Presenting the ButtonExtender for Border Color, Border Width and Corner Radius function with the @IBDesignable and @IBInspectable in the Swift Language.
By making some corner radius and colors, You will get neat and clean output.
Github
Find IBButtonExtender on github 🙂
Check other articles on Swift Language.
All suggestions are acceptable. Put it in the comments!
Happy Coding 🙂