Created
October 26, 2012 11:41
-
-
Save willryanuk/3958325 to your computer and use it in GitHub Desktop.
This is a UISwitch with a block based hander for value change control events
This file contains hidden or 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
// | |
// ZUISwitch.h | |
// zeebox | |
// | |
// Created by Will on 26/10/2012. | |
// Copyright (c) 2012 Electric Labs. All rights reserved. | |
// | |
@interface ZUISwitch : UISwitch | |
- (void)onValueChange:(void (^)(UISwitch *uiSwitch)) block; | |
@end |
This file contains hidden or 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
// | |
// ZUISwitch.m | |
// zeebox | |
// | |
// Created by Will on 26/10/2012. | |
// Copyright (c) 2012 zeebox. All rights reserved. | |
// | |
#import "ZUISwitch.h" | |
@interface ZUISwitch () | |
@property (nonatomic, copy) void (^valueChangeBlock)(UISwitch *uiSwitch); | |
@end | |
@implementation ZUISwitch | |
- (void) awakeFromNib { | |
[self commonInit]; | |
} | |
- (id)init { | |
self = [super init]; | |
if (self) { | |
[self commonInit]; | |
} | |
return self; | |
} | |
- (void)commonInit { | |
[self addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged]; | |
} | |
- (void)onValueChange:(void (^)(UISwitch *uiSwitch)) block { | |
self.valueChangeBlock = block; | |
} | |
- (void)switchValueChanged:(id)sender { | |
if(_valueChangeBlock) { | |
_valueChangeBlock(self); | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment