0

I have customised UI button and create some properties with IBInspectable. However, I also need the same property for selected or highlighted state and can be inspected in Interface Builder. I want to know if it can be achieved?

Here is the customized button I created

    @IBDesignable
    class ImageLabelButton: UIButton{
    /*
     // Only override draw() if you perform custom drawing.
     // An empty implementation adversely affects performance during animation.
     override func draw(_ rect: CGRect) {
     // Drawing code
     }
     */
    let buttonImgView = UIImageView()
    let buttonLabel = UILabel()
    //    let stackView = UIStackView()



    // Override property observors
    @IBInspectable
    var textColor:UIColor? {
        get {
            return buttonLabel.textColor
        }
        set(newValue) {
            self.buttonLabel.textColor = newValue
        }
    }
 }

I want to create a IBInspectable property for other states as well. Can it be done? Thanks!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Patrick
  • 11
  • 1

1 Answers1

0

Short answer? No. Interface Builder cannot "process" code.

  • I have a need to know when my app is in portrait or landscape orientation (various slider controls are on the bottom or right depending on this).

Can I use IB for this? Not if I need to know on an iPad... it's size class is (wR hR) unless the slide out or split screen is there. I can "design" something for each orientation, but even Apple - WWDC'16, Making Apps Adaptive, Part 2 - ended up putting code into viewWillLayoutSubviews() for this.

  • Put a UIButton on your storyboard. Can you process a tap? Put a UISlider on the storyboard. Can you pan it left or right?

You are asking a design time tool to process run time actions.

So again, you can't make certain button states IBDesignable.