1

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.

Sahil
  • 9,096
  • 3
  • 25
  • 29

2 Answers2

5

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
    }
}
DonMag
  • 69,424
  • 5
  • 50
  • 86
  • This is not what i want(Storyboard does not support the feature i want now) and Thanks for your time. – Sahil Mar 29 '17 at 05:03
  • Thanks for this suggestion, this helped me out. I needed to associate identifiers with the segments of a custom UISegmentedControl and a string like this, while not ideal, worked nicely. – John Stephen Feb 28 '18 at 01:00
  • 1
    @Rob Yes, you're right. I guess this is the only way to create what I wanted. – Sahil May 09 '18 at 04:59
0

@IBInspectable properties is backed by user-defined runtime attribute which is not support Segment data type yet. So I believe that Storyboard does not support the feature you want.