Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring @IBInspectable Attribute Inspector controls

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:

enter image description here

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.

like image 656
Anna Dickinson Avatar asked Dec 29 '14 16:12

Anna Dickinson


1 Answers

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.

like image 135
Caleb Avatar answered Nov 14 '22 16:11

Caleb