问题描述
我想创建自定义控件(如段控件),但是我不明白如何创建这种Segment
IBInspectable属性.我的意思是根据Segments
,它的元素在增加.据我所知,@IBInspectable
中不支持数组.
I 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
.
推荐答案
您还不能创建该类型的@IBInspectable
(至今),但是...
You can't create that type of @IBInspectable
(yet), but...
您可以将String变量定义为@IBInspectable
var,并向其中添加多行.然后使用didSet
方法将字符串拆分成一个供内部使用的数组(例如)...
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)...
遵循以下原则:
private var internalTextArray: [String]?
@IBInspectable var segments: String = "" {
didSet {
internalTextArray = segments.components(separatedBy: "\n")
// do something with the split-up lines of text
}
}
这篇关于如何创建类似于IBInspectable属性的段控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!