【发布时间】:2017-03-28 16:54:31
【问题描述】:
我想创建像段控件这样的自定义控件但我无法理解如何创建这种SegmentIBInspectable 属性。我的意思是它的元素根据Segments 增加。据我所知,@IBInspectable 不支持数组。
【问题讨论】:
标签: ios swift swift3 ibdesignable ibinspectable
我想创建像段控件这样的自定义控件但我无法理解如何创建这种SegmentIBInspectable 属性。我的意思是它的元素根据Segments 增加。据我所知,@IBInspectable 不支持数组。
【问题讨论】:
标签: ios swift swift3 ibdesignable ibinspectable
你不能创建那种类型的@IBInspectable(目前),但是......
您可以将字符串变量定义为@IBInspectable var,并向其添加多行。然后有一个didSet 方法将字符串拆分为您在内部使用的数组(例如)...
类似的东西:
private var internalTextArray: [String]?
@IBInspectable var segments: String = "" {
didSet {
internalTextArray = segments.components(separatedBy: "\n")
// do something with the split-up lines of text
}
}
【讨论】:
@IBInspectable 属性由 user-defined runtime attribute 支持,它尚不支持 Segment 数据类型。所以我认为 Storyboard 不支持你想要的功能。
【讨论】: