I have created custom UIView class with IBDesignable method enable in it. Inside the class, I have added few IBInspectable properties looks something like this,
Swift 4.0 - Snippet:
@IBDesignable
class SegmentView: UIView {
@IBInspectable var borderWidth = 0.0 {
didSet{
layer.borderWidth = CGFloat(borderWidth)
}
}
@IBInspectable var borderColor = UIColor.clear {
didSet{
layer.borderColor = borderColor.cgColor
}
}
}
Whenever I am using this class in StoryBoard for UIView element, I am unable to view above declared IBInspectable properties in storyboard -> View -> View Property Tab, for reference please check below-attached screenshot.
Issue: In the above segment view header, there are no IBInspectable properties available.
Can someone help me to resolve my above issue?
Thanks in advance.
You need to explicitly declare the variable type, like:
@IBDesignable
class SegmentView: UIView {
@IBInspectable var borderWidth: CGFloat = 0.0 {
didSet {
layer.borderWidth = CGFloat(borderWidth)
}
}
@IBInspectable var borderColor: UIColor = .clear {
didSet {
layer.borderColor = borderColor.cgColor
}
}
}