From 6a01bbbe20edb0aeb8f80cec979775529ddb3603 Mon Sep 17 00:00:00 2001 From: Taesun Park Date: Mon, 26 Jun 2017 18:24:58 +0900 Subject: [PATCH] * Change: processing IncludeButton data -> runtime method --- TezButton/TezButton.h | 3 ++- TezButton/TezButton.m | 11 +++++++++++ TezButtonExample/ViewController.m | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/TezButton/TezButton.h b/TezButton/TezButton.h index a2883b3..32c0bec 100644 --- a/TezButton/TezButton.h +++ b/TezButton/TezButton.h @@ -331,5 +331,6 @@ #pragma mark - Include data Button /** Incluging data button */ @interface IncludeDataButton : UIButton -@property (nonatomic, strong) NSDictionary* info; +- (void)setData:(id)data; +- (id)data; @end diff --git a/TezButton/TezButton.m b/TezButton/TezButton.m index 47d9d68..2bd030f 100644 --- a/TezButton/TezButton.m +++ b/TezButton/TezButton.m @@ -6,11 +6,13 @@ // #import "TezButton.h" +#import static const double DefaultMagnification = 1; static const CGFloat DefaultFontSize = 13; static const CGFloat DefaultCornerRadius = 8; static const UIRectCorner DefaultCornerOption = UIRectCornerAllCorners; +static void *DataKey = "DataKey"; #pragma mark - TezButton @interface TezButton() @@ -622,4 +624,13 @@ - (void) drawRect:(CGRect)rect { #pragma mark - Include data Button @implementation IncludeDataButton : UIButton +- (void)setData:(id)data { + objc_setAssociatedObject(self, DataKey, data, OBJC_ASSOCIATION_RETAIN); +} + +- (id)data { + id data = objc_getAssociatedObject(self, DataKey); + + return data; +} @end diff --git a/TezButtonExample/ViewController.m b/TezButtonExample/ViewController.m index e61e093..4d521fd 100644 --- a/TezButtonExample/ViewController.m +++ b/TezButtonExample/ViewController.m @@ -142,7 +142,7 @@ - (void)makeButtons { // Include Data option IncludeDataButton* includeDataBtn = [[IncludeDataButton alloc] initWithFrame:CGRectMake(originX, originY, self.view.frame.size.width/2 - 20*1.5, 60)]; - [includeDataBtn setInfo:[NSDictionary new]]; + [includeDataBtn setData:[NSDictionary new]]; [includeDataBtn setBackgroundColor:colorPink]; [includeDataBtn setTitleColor:colorWhite forState:UIControlStateNormal]; [includeDataBtn setTitle:@"Include data btn" forState:UIControlStateNormal];