henrik-dmg
henrik-dmg

Reputation: 1493

Make UIButton accessible in Interface Builder

I'm working on a little project which adds a little bar on the bottom of the screen, similar to UITabBar (see screenshot below). It's an @IBDesignable class. The blue boxes you can see are buttons with placeholder images. Now my question is, can I somehow open up these buttons to the IB as well? Like when I click one of the boxes I get the attribute inspector for that specific button? Thanks in advance

enter image description here

Upvotes: 0

Views: 216

Answers (1)

ahagbani
ahagbani

Reputation: 132

Sorry I miss understood the question. No you can't have a UIButton as an attribute in the interface builder. I believe @IBInspectable only supports a certain group of types.

These are the types that I know, maybe there are more types.

  • Int
  • CGFloat
  • Double
  • String
  • Bool
  • CGPoint
  • CGSize
  • CGRect
  • UIColor
  • UIImage

However, you can do something like the example below and apply that to other properties:

@IBDesignable class CustomTabBar: UITabBar {
    var button1: CustomButton!
    var button2: CustomButton!
    var button3: CustomButton!

    @IBInspectable var button1Title: String? {
        get {
            return button1.titleLabel?.text
        } set {
            button1.setTitle(newValue, for: .normal)
        }
    }
}

Upvotes: 1

Related Questions