3

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.

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
  • 2
    Avoding the questionability of what you are doing, while initWithCoder: can be used without Storyboard, it is unlikely that it will be, so I don't see the problem in implementing a subclass of UIView that has an additional readonly @property initializedWithCoder that determines if the View should be adjusted. – sammoore Nov 24 '14 at 06:55

0 Answers0