【问题标题】:How to create segment control like IBInspectable properties?如何创建像 IBInspectable 属性这样的段控件?
【发布时间】:2017-03-28 16:54:31
【问题描述】:

我想创建像段控件这样的自定义控件但我无法理解如何创建这种SegmentIBInspectable 属性。我的意思是它的元素根据Segments 增加。据我所知,@IBInspectable 不支持数组。

【问题讨论】:

    标签: ios swift swift3 ibdesignable ibinspectable


    【解决方案1】:

    你不能创建那种类型的@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
        }
    }
    

    【讨论】:

    • 这不是我想要的(Storyboard 不支持我现在想要的功能)并且感谢您的时间。
    • 感谢您的建议,这帮助了我。我需要将标识符与自定义 UISegmentedControl 的段和这样的字符串相关联,虽然不理想,但效果很好。
    • @Rob 是的,你是对的。我想这是创造我想要的东西的唯一方法。
    【解决方案2】:

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

    【讨论】:

    • 真的! Storyboard 不支持我想要的功能。
    猜你喜欢
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多