Created
October 22, 2013 13:20
-
-
Save elpsk/7100640 to your computer and use it in GitHub Desktop.
foreach label
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 APViewController () | |
{ | |
NSMutableArray *_Labels; | |
} | |
- ( void ) forEachLabel: ( void (^)( UILabel * label ) ) block; | |
@end | |
@implementation APViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
_Labels = [[NSMutableArray alloc] init]; | |
for ( int i=1; i<=15; i++ ) | |
{ | |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake( i*20, 200, 20, 20 )]; | |
label.text = @"x"; | |
label.textColor = [ UIColor whiteColor ]; | |
[ self.view addSubview:label ]; | |
[ _Labels addObject:label ]; | |
} | |
} | |
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event | |
{ | |
[ self forEachLabel:^(UILabel *label) { | |
label.textColor = [ UIColor yellowColor ]; | |
}]; | |
} | |
- ( void ) forEachLabel: ( void (^)( UILabel * ) ) block | |
{ | |
for( UILabel * label in _Labels ) | |
block( label ); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment