Last active
December 17, 2015 20:39
-
-
Save andrewsardone/5669432 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface AbstractViewController : UIViewController | |
@property (nonatomic, strong) Class specialButtonClass; | |
@property (nonatomic, strong) IBOutlet UIButton *specialButton; // laid out in nib | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AbstractViewController.h" | |
#import "UIButton+NLDuplicate.h" | |
@implementation NLRootViewControllerPad | |
#pragma mark Object Lifecycle | |
- (id)init | |
{ | |
NSString *nibName = NSStringFromClass(AbstractViewController.class); | |
self = [super initWithNibName:nibName | |
bundle:nil]; | |
return self; | |
} | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | |
{ | |
return [self init]; | |
} | |
#pragma mark UIView lifecycle | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
[self _updateSpecialButtonWithCustomClass:self.specialButtonClass]; | |
} | |
- (void)_updateSpecialButtonWithCustomClass:(Class)class | |
{ | |
self.specialButton = ([self _swapButton:self.specialButton | |
withDuplicateFromClass:class | |
inView:self.view]) ?: self.specialButton; | |
} | |
- (UIButton *)_swapButton:(UIButton *)button withDuplicateFromClass:(Class)class inView:(UIView *)view | |
{ | |
if (class == nil) return nil; | |
UIButton *oldButton = button; | |
UIButton *newButton = [UIButton nl_duplicateButton:button withClass:class]; | |
[view addSubview:newButton]; | |
[oldButton removeFromSuperview]; | |
return newButton; | |
} | |
- (void)setSpecialButtonClass:(Class)specialButtonClass | |
{ | |
_specialButtonClass = specialButtonClass; | |
[self _updateSpecialButtonWithCustomClass:_specialButtonClass]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
#import "AbstractViewController.h" | |
@interface AbstractViewController : AbstractViewController | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ConcreteViewController.h" | |
@interface AwesomeButton : UIButton | |
@end | |
@implementation AwesomeButton | |
- (void)drawRect:(CGRect)rect | |
{ | |
[super drawRect:rect]; | |
// custom drawing | |
} | |
@end | |
@implementation ConcreteViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
self.specialButtonClass = AwesomeButton.class; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment