11

While attempting to modify the Apple tutorial found here on IBinspectable properties for my own project I have run into a major roadblock.

I defined a simple button subclass:

import UIKit

@IBDesignable public class SocialMediaLoginButton: UIButton {

  private var _loginType: SocialMediaLoginType = .facebook

  @IBInspectable public var loginType: SocialMediaLoginType 
              = SocialMediaLoginType.facebook {

      didSet {
          self._loginType = loginType
      }
  }
}

And then added a UIButton to my storyboard which I then selected the CustomClass as the above type. When I switch over to the Attributes inspector the property is not there for me to adjust. I have no idea what is going on:

Attributes inspector

I have looked up other questions however there are either extremely outdated or have no answers on the app developer forum.

I have tried:

  1. Manually refreshing the views
  2. closing and reopening xcode
  3. removing and re-adding the control
  4. adding different controls like UIView and attempting same thing

None of these have worked. I am at a loss for how to fix this. I am using Xcode 8.3.3

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    Please check this answer https://stackoverflow.com/questions/27432736/how-to-create-an-ibinspectable-of-type-enum – Reinier Melian Jul 22 '17 at 18:57
  • Thank you I just found that. So I am just stuck with either a bunch of bools, magic strings, or opaque numbers. –  Jul 22 '17 at 19:00

2 Answers2

9

Interface Builder supports the inspection of basic types (and their corresponding optionals), including: Booleans, numbers, strings, as well as CGRect, CGSize, CGPoint, and UIColor.

I think your type does not work with interface builder.

Wilson Campusano
  • 616
  • 9
  • 21
8

To add to Wilson answer, you MUST EXPLICITLY specify the type (Int, String, etc.) for it to show.

Zeev Vax
  • 914
  • 7
  • 13
  • I had this problem. For example, `@IBInspectable var lineWidth = CGFloat(2.0)` will **not** work; you have to be explicit: `@IBInspectable var lineWidth: CGFloat = 2.0`. – Steve G. Jan 16 '20 at 09:43