0

I have an IBDesignable class which has an IBInspectable value: Int

value is basically the number of balls shown within the IBDesignable class

so I have a setup() func which adds the correct imageViews (one for each ball) using for _ 0 ..< value { }

But when changing the value I don't see the new number of balls in Interface Builder

Perhaps But Designables: Updating stays there...

How do you make setup() be executed every time Value changes ?

Thanks in advance

TheBearF8
  • 375
  • 1
  • 3
  • 14

1 Answers1

0

Try this code

@IBDesignable
class SNButton:UIButton{

    @IBInspectable var val: Int = 0

    override func layoutSubviews() {
        super.layoutSubviews()


        for i in 0...val {
         let ui = UIImageView(frame: CGRect(x: i, y: 0, width: 20, height: 20))
            ui.backgroundColor = UIColor.red
            self.addSubview(ui)
        }
      }        

    }

But I do not advise you to do this because you will notice that storyboard has become very slow

a.masri
  • 2,439
  • 1
  • 14
  • 32