I'm trying to use the IB Designable and IB Inspectable in my UIButton but seems there are some errors.
In the Issue Navigator, the bundle file:
Storyboard : IB Designables : Failed to update auto layout status: Failed to load designabled from path (null)
So I wonder if there are any configurations to do to use it in a static lib or something like that ?
This is
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface CustomUIButton : UIButton
@property (nonatomic) IBInspectable int cornerRadius;
@end
My custom button I want to live render is inside a view controller
Unfortunately it isn't possible to use
IBDesignables
with static libraries (or static frameworks).This isn't a great answer but I want to give some context on why.
It seems that the way Interface Builder loads classes to be shown as designables is by actually dynamically loading the dynamic framework that you create (and not your app's binary), and using the classes directly (after changing them using the Objective-C runtime quite a bit).
You can see that Interface Builder isn't loading your app, and just the individual frameworks with these steps:
IBDesignable
IBDesignable
classIBDesignables
directory, you can see that only your framework target has been built.Interface builder actually loads your framework using
dlopen
manually. You can also see that to facilitate this when building your framework, Interface Builder actually adds 2RPATH
s to your binary, so the dependencies can be found in the custom paths (you can view this withotool -L frameworkbinary
). This method of loading your binary isn't possible with static libraries.For what it's worth I think the best workaround for this is to build dynamic frameworks, instead of static libraries, but only for
IBDesignable
builds. You'll have to do some configuration work to do this, and it isn't easy to work around Xcode to have this work, but if you try it, you can use either the build path, or the environment, to differentiateIBDesignable
builds vs "normal" builds.