Skip to content

Commit

Permalink
* Change: processing IncludeButton data -> runtime method
Browse files Browse the repository at this point in the history
  • Loading branch information
Taesun Park committed Jun 26, 2017
1 parent c412139 commit 6a01bbb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion TezButton/TezButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions TezButton/TezButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
//

#import "TezButton.h"
#import <objc/runtime.h>

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()
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion TezButtonExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 6a01bbb

Please sign in to comment.