如何创建像IBInspectable属性一样的段控件?

时间:2017-03-28 16:54:32

标签: ios swift swift3 ibdesignable ibinspectable

enter image description here我想创建自定义控件,例如段控件但是我无法理解如何创建这种Segment IBInspectable属性。我的意思是它的元素根据Segments而增加。据我所知,@IBInspectable中没有数组支持。

2 个答案:

答案 0 :(得分:4)

您无法创建@IBInspectable那种类型,但是......

您可以将String变量定义为@IBInspectable var,并为其添加多行。然后使用didSet方法将字符串拆分为内部使用的数组(例如)...

enter image description here

这些方面的东西:

private var internalTextArray: [String]?

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

答案 1 :(得分:0)

@IBInspectable属性由user-defined runtime attribute支持,但尚未支持Segment数据类型。所以我认为Storyboard不支持你想要的功能。

相关问题