-1

I would like all subclasses of UIView to have a stored property IBInspectable. Unfortunately I can't use an extension of UIView, because in an extension, an IBInspectable cannot be a stored property.

The best solution I have right now is to create base sublcasses of all my UIViews (BaseUIView, BaseUILabel, BaseUIImageView, etc.), place the same IBInspectable in all of those, and have all my views be one of the base classes.

I'm not crazy about this solution.. .it's a little messy, and the list of base classes will probably need to be continually be updated. Does anyone know a better solution?

Michael Lee
  • 339
  • 3
  • 11

1 Answers1

0

Personal I would avoid using IBInspectable, they are nothing but trouble. Can cause Storyboards to crash or take forever to load/lag.

What I would do is brake down consistent styles into class components and do all the styling there. There are other ways you can do this, all have their pro/cons. But do yourself a favour and keep away from IBInspectable.

OneCommentMan
  • 147
  • 1
  • 6
  • The goal is to allow a client, who is not a developer but somewhat familiar with storyboards, to make modifications. Besides the issues I mentioned, this approach is working well, I haven't had any crash/loading issues. Do you recall which version of xcode had these problems? – Michael Lee Mar 22 '23 at 20:45
  • Might find your answer here, but reading through some people are also saying it causes crashes. https://stackoverflow.com/questions/29906855/can-you-add-ibdesignable-properties-to-uiview-using-categories-extensions For me it started to crash when I had multiple VC in one storyboard and each VC used IBInspectable. Thats when I switched to Xib files or code based UI and stopped using it. But good luck. – OneCommentMan Mar 23 '23 at 08:02