码迷,mamicode.com
首页 > 其他好文 > 详细

Rumtime之关联

时间:2015-06-10 18:56:16      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:


UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    
    btn.tag = 100;
    NSLog(@"%d",btn.tag);
    objc_setAssociatedObject(self, &overviewKey, btn, OBJC_ASSOCIATION_RETAIN);
    
    UIButton * btn1 = objc_getAssociatedObject(self, &overviewKey);
    btn1.tag  =111;
    NSLog(@"%d",btn1.tag);

 

static char flashColorKey;
- (void) setFlashColor:(UIColor *) flashColor{
    objc_setAssociatedObject(self, &flashColorKey, flashColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (UIColor *) getFlashColor{
    
    return objc_getAssociatedObject(self, &flashColorKey);
}

通过关联之后传值动态获取

Rumtime之关联

标签:

原文地址:http://www.cnblogs.com/keyan1102/p/4566766.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!