Search code examples
iosxcodeinterface-builderibdesignableibinspectable

IBInspectable property set at design time not keeping value


We are in the process of implementing IBInspectable into a large app in hopes of allowing some settings to be set in Interface Builder to reduce the amount of code in our views. I don't have much experience with IBInspectable/IBDesignable and am looking for some answers and/or clarification on what I'm doing wrong.

I have declared a property in a UITableViewCell subclass as follows:

@property (nonatomic,strong) IBInspectable UIColor* backgroundColor;

When declaring the property like this, I get an option to set that color in Interface Builder > Attributes Inspector, which is to be expected. However when I set the color, the value for _backgroundColor is nil at runtime.

[_labelLoginBackground setBackgroundColor:_backgroundColor];

Could someone clarify what might be going here? Thanks!


Solution

  • UITableViewCell is a subclass of UIView, which already contains a property named "backgroundColor". Do 1 of the following:

    1. Rename your own "backgroundColor" property to "loginBackgroundColor" and start debugging from there.

    OR

    1. Do not create a redundant property. Set the background color using the selection widget that is already present in Interface Builder before you ever add IBInspectable.

    enter image description here