Rumtime之关联

 
 
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);
}

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

你可能感兴趣的:(time)