Configuring @IBInspectable Attribute Inspector controls

╄→尐↘猪︶ㄣ 提交于 2019-12-18 14:45:29

问题


Is it possible to configure how @IBInspectable properties are displayed and/or controlled in the Attribute Inspector? For example, I have a CGFloat property "Overlay Alpha" which shows up in the inspector like this:

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?

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?

Just wondering how much I can customize the display. I'm trying to see how far I can push the IBDesignable feature into making IB an actual UI design tool.


回答1:


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.



来源:https://stackoverflow.com/questions/27692868/configuring-ibinspectable-attribute-inspector-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!