1

If I want my UIView to perform custom logic on layoutSubviews, is the only way to accomplish this by making my own subclass of UIView and implementing the method? I think I remember something from an example somewhere about being able to implement a method just for a particular instance of a class, but I don't remember what the syntax was, or if that is even a thing.

phosphoer
  • 433
  • 6
  • 16

1 Answers1

1

if you want to perform something for that one view then the best course it to Subclass and override for that one view.

If you want it to happen on all views then you will need to method swizzle to change the layoutSubviews to another method that you specify, and include that category in the _prefix.pch file

Method Swizzling is not to be taken lightly but you can check out my explanation of it here

I recommend the first option. Subclass and override. Just remember to call the [super layoutSubviews] method to complete the chain. (unless blocking that chain is the intention)

Community
  • 1
  • 1
The Lazy Coder
  • 11,560
  • 4
  • 51
  • 69
  • Not a problem. I have been on iOS for about a year and a half. If it weren't for the help I received from stackoverflow I would not have gotten as far as I am now. So I am glad to help :) – The Lazy Coder Jun 23 '12 at 00:45