Skip to content

Instantly share code, notes, and snippets.

@AlanQuatermain
Created September 12, 2011 14:14
Show Gist options
  • Save AlanQuatermain/1211349 to your computer and use it in GitHub Desktop.
Save AlanQuatermain/1211349 to your computer and use it in GitHub Desktop.
Sharing UIView subclasses between iPhone and iPad? Make your life easier with device-specific -layoutSubviews (or -drawRect, etc.) methods. Make the Objective-C runtime work for YOU!
+ (void) initialize
{
if ( self != [KBCommentEditorView class] )
return;
// install the device-appropriate version of -layoutSubviews
Method m1 = class_getInstanceMethod(self, @selector(layoutSubviews));
Method m2 = class_getInstanceMethod(self, IsPad() ? @selector(layoutSubviewsIPad) : @selector(layoutSubviewsIPhone));
method_exchangeImplementations(m1, m2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment