-1

I'm maybe too complicated, but here is what I want:

@IBDesignable
class A: UIView {
    @IBInspectable var title: String = "" {
        didSet {
            setNeedsLayout()
        }
    }
}

@IBDesignable
class B: UIView {
    var firstView: A = A()
    var secondView: A = A()
}

The B class have 2 @IBDesignable classes, so if I want to customize B directly in Interface Builder, I can't as I don't have access to the 2 A classes.

At first I create a protocol to list all elements in A class, but when a view need 2 or more item of A class, I can't use this.

Do someone have an idea to have only 1 B class in my storyboard and can customize both A classes?

6
  • Not very sure, but do you think making these variables as public might help. I'll try to check this via coding it. Commented Mar 1, 2019 at 10:51
  • I try a lot of things in case some magic happens but no. Just check again and 'Show the attributes inspector' tab is still empty of custom @IBInspectable.
    – Dam
    Commented Mar 1, 2019 at 11:00
  • 1
    Give B the inspectable properties, e.g. firstViewTitle and secondViewTitle.
    – matt
    Commented Mar 1, 2019 at 13:29
  • @matt My main problem is that if tomorrow I add an IBInspectable titleColor to the A class, I have nothing to prevent me to didn't forget to add 2 IBInspectable var to B class.
    – Dam
    Commented Mar 1, 2019 at 13:44
  • Too bad. If you cannot see the A in the storyboard, there is nothing to be inspect. You can only inspect what you can see.
    – matt
    Commented Mar 1, 2019 at 13:46

1 Answer 1

0

Not very sure if your this is possible. This is not usually possible even when you use Apple Library classes, for example a UIButton has a UIView and also a UILabel.

Though these different classes and some things are possible by overriding as explained here

But I can provide you a hack here. In the object that you create for Object B in storyboard, you can add User Defined Runtime Attributes as follows -

firstView.title & secondView.title

I know this might not be the answer you are looking for, but thats just a way around.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.