Search code examples
iosswiftswift3ibdesignableibinspectable

How to create segment control like IBInspectable properties?


enter image description hereI want to create custom control like segment control But i'm not able to understand how to create this kind of Segment IBInspectable properties. i mean it's elements increasing according to Segments. as i know there is no support of array in @IBInspectable.


Solution

  • You can't create that type of @IBInspectable (yet), but...

    You can define a String variable as an @IBInspectable var, and add multiple lines to it. Then have a didSet method split the string into an array which you use internally (for example)...

    enter image description here

    Something along these lines:

    private var internalTextArray: [String]?
    
    @IBInspectable var segments: String = "" {
        didSet {
            internalTextArray = segments.components(separatedBy: "\n")
            // do something with the split-up lines of text
        }
    }