Configuring @IBInspectable Attribute Inspector controls

前端 未结 1 1529
春和景丽
春和景丽 2021-01-01 19:14

Is it possible to configure how @IBInspectable properties are displayed and/or controlled in the Attribute Inspector? For example, I have a CGFloat

1条回答
  •  隐瞒了意图╮
    2021-01-01 20:07

    The problem is that the adjustor up/down arrows only update in integral (+/- 1) steps. I want them to update in small steps, say, +/- 0.05 increments. Is there any way to do that?

    Lack of any documentation explaining how to do it and the fact that your question is 3+ years old suggest that you can't actually change the increment value of the stepper for your inspectable properties in IB.

    What you can do, however, is to create another property based on the one you want to adjust, and scale that one so that increments of 1 correspond to steps of the size you want. For example, designers are probably used to thinking about opacity in terms of percentages, so you could create an alphaPercent property with getters and setters that scale the alpha property up by 100:

    @IBInspectable var alphaPercent : CGFloat {
        get {
            return self.alpha * 100
        }
        set(percentage) {
            self.alpha = percentage / 100
        }
    }
    

    If you add that property to an @IBDesignable view you'll be able to use the stepper to change the view's opacity by 1% with each click.

    How about other properties of the controls? Can you display a slider for a CGFloat instead of a numeric field? Can you add a tooltip? Can you add static descriptive text?

    None of that is currently possible. If you have a long-term need for less technical users to make user interface adjustments (e.g. if you're skinning the same basic app for a number of different customers), it might make sense to build a version of your app that provides an edit mode. Looking at the Tweaks framework from Facebook might give you some ideas.

    0 讨论(0)
提交回复
热议问题