Skip to content

Instantly share code, notes, and snippets.

View kielgillard's full-sized avatar

Kiel Gillard kielgillard

View GitHub Profile
@AlanQuatermain
AlanQuatermain / gist:1211349
Created September 12, 2011 14:14
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);
}