Configuring @IBInspectable Attribute Inspector controls
Asked Answered
W

1

15

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.

Wagtail answered 29/12, 2014 at 16:56 Comment(7)
Did you ever find a solution to this question? – Fluidextract
No, I never did... πŸ™ – Wagtail
Too bad, thanks for posting, though! – Fluidextract
Did you see if using different types had an effect (i.e. double, long, float, NSInteger, etc.)? – Amalekite
Did anyone find any solution? – Elective
Seems like there's no way to achieve this in Xcode (yet). Whatever "type-dance" you make with @IBInspectable, Xcode will always render those to default controls (eg. color picker for UIColor, value adjustors for number based types, etc..). However, wonder what would happen if you simply type decimal value directly in the filed ? (that works when setting a NSLayoutConstraint.constant). Some references by @Nate Cook and others : gist.github.com/natecook1000/4269059121ec247fbb90, medium.com/anantha-krishnan-k-g/… – Inexactitude
Yeah, kinda looks like Apple hasn't evolved this feature. I don't think it's changed at all since it was introduced a few years ago. Workflow-wise, I've abandoned using IBDesignable in the way I described in my original question. I occasionally use it to tweak the look of things. But, then I comment out the @IBDesignable directive after I'm done. It's unreliable, a time sink to implement, and severely bogs down Xcode. – Wagtail
S
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.

Selfseeking answered 12/2, 2018 at 18:24 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.