Last active
December 15, 2015 14:09
-
-
Save irace/5272146 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
@interface UntoggleableSwitch : UISwitch | |
@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 "UntoggleableSwitch.h" | |
@interface ProxyControl : UIControl | |
@property (nonatomic, weak) UIControl *actualControl; | |
@end | |
@interface UntoggleableSwitch() | |
@property (nonatomic, strong) ProxyControl *proxyControl; | |
@end | |
@implementation UntoggleableSwitch | |
#pragma mark - NSObject | |
- (id)init { | |
if (self = [super init]) { | |
self.proxyControl = [[ProxyControl alloc] initWithFrame:self.frame]; | |
self.proxyControl.actualControl = self; | |
[self addSubview:self.proxyControl]; | |
} | |
return self; | |
} | |
#pragma mark - UIControl | |
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents { | |
[self.proxyControl addTarget:target action:action forControlEvents:controlEvents]; | |
} | |
@end | |
@implementation ProxyControl | |
#pragma mark - UIControl | |
- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event { | |
UIControl *actualControl = self.actualControl; | |
[actualControl sendAction:action to:target forEvent:event]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment