Check whether UIView is loaded from a Nib/Storyboard or was created programmatically

236 views Asked by At

Is there any way to identify whether a UIView is loaded from a nib file/Storyboard, or instantiated dynamically from user code? I am creating a custom UIView subclass so I have full access to instance methods.

Would checking whether initWithCoder: is called a good idea, or are there other ways too?

For anyone who wonders why I need such functionality: I am developing a library where I want to smart-resize some views according to their content only if they are programmatically created (user won't bother with initialization code, adding layout constraints etc and I will have a simple class method initializer). If user has designed it in Interface Builder, they obviously want to see it as they designed it (I am using IBDesignable/IBInspectable attributes too so IB will heavily be used), so I won't be touching their design.

0

There are 0 answers