Created
April 23, 2012 04:37
Revisions
-
joshdholtz revised this gist
Jun 1, 2012 . 2 changed files with 63 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ // // UIButton+Block.h // BoothTag // // Created by Josh Holtz on 4/22/12. // Copyright (c) 2012 Josh Holtz. All rights reserved. // #define kUIButtonBlockTouchUpInside @"TouchInside" #import <UIKit/UIKit.h> @interface UIButton (Block) @property (nonatomic, strong) NSMutableDictionary *actions; - (void) setAction:(NSString*)action withBlock:(void(^)())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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ // // UIButton+Block.m // BoothTag // // Created by Josh Holtz on 4/22/12. // Copyright (c) 2012 Josh Holtz. All rights reserved. // #import "UIButton+Block.h" #import "/usr/include/objc/runtime.h" @implementation UIButton (Block) static char overviewKey; @dynamic actions; - (void) setAction:(NSString*)action withBlock:(void(^)())block { if ([self actions] == nil) { [self setActions:[[NSMutableDictionary alloc] init]]; } [[self actions] setObject:[block copy] forKey:action]; if ([kUIButtonBlockTouchUpInside isEqualToString:action]) { [self addTarget:self action:@selector(doTouchUpInside:) forControlEvents:UIControlEventTouchUpInside]; } } - (void)setActions:(NSMutableDictionary*)actions { objc_setAssociatedObject (self, &overviewKey,actions,OBJC_ASSOCIATION_RETAIN_NONATOMIC); } - (NSMutableDictionary*)actions { return objc_getAssociatedObject(self, &overviewKey); } - (void)doTouchUpInside:(id)sender { void(^block)(); block = [[self actions] objectForKey:kUIButtonBlockTouchUpInside]; block(); } -
joshdholtz created this gist
Apr 23, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ // // UIButton+Block.h // BoothTag // // Created by Josh Holtz on 4/22/12. // Copyright (c) 2012 Josh Holtz. All rights reserved. // #define kUIButtonBlockTouchUpInside @"TouchInside" #import <UIKit/UIKit.h> @interface UIButton (Block) @property (nonatomic, strong) NSMutableDictionary *actions; - (void) setAction:(NSString*)action withBlock:(void(^)())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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ // // UIButton+Block.m // BoothTag // // Created by Josh Holtz on 4/22/12. // Copyright (c) 2012 Josh Holtz. All rights reserved. // #import "UIButton+Block.h" #import "/usr/include/objc/runtime.h" @implementation UIButton (Block) static char overviewKey; @dynamic actions; - (void) setAction:(NSString*)action withBlock:(void(^)())block { if ([self actions] == nil) { [self setActions:[[NSMutableDictionary alloc] init]]; } [[self actions] setObject:block forKey:action]; if ([kUIButtonBlockTouchUpInside isEqualToString:action]) { [self addTarget:self action:@selector(doTouchUpInside:) forControlEvents:UIControlEventTouchUpInside]; } } - (void)setActions:(NSMutableDictionary*)actions { objc_setAssociatedObject (self, &overviewKey,actions,OBJC_ASSOCIATION_RETAIN_NONATOMIC); } - (NSMutableDictionary*)actions { return objc_getAssociatedObject(self, &overviewKey); } - (void)doTouchUpInside:(id)sender { void(^block)(); block = [[self actions] objectForKey:kUIButtonBlockTouchUpInside]; block(); } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ ... [button setAction:kUIButtonBlockTouchUpInside withBlock:^{ NSString* launchUrl = @"http://joshholtz.com"; [[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]]; }]; ..