0

I'm trying to write an extension method on UIView that will be called whenever a view is initialized, meaning that the method should be invoked without my having to call on it explicitly. Is there a way to accomplish this such as with key-value observing?

etayluz
  • 15,920
  • 23
  • 106
  • 151
  • Is your method an instance method or class method? – Tony Aug 21 '16 at 07:46
  • 1
    This is most probably a very very bad design and you should probably ask yourself whether you really need to do this for every view. But this is doable. Google "method swizzling" and swizzle the init method of UIView. This can't be done with Swift extensions or KVO. – deadbeef Aug 21 '16 at 11:16
  • 1
    This sounds like an [XY problem](http://meta.stackexchange.com/q/66377/244435). What exactly are you trying to do? – nhgrif Aug 22 '16 at 12:09
  • @nhgrif, I'm trying to write a subclass/extension of UIView that will set the frame of a view proportionally to the screen size. I find that it's a pain to scale up my design with autolayout. – etayluz Aug 23 '16 at 04:15

0 Answers0