UIButton+zz.h文件如下:
@interface UIButton (zz)
@property (nonatomic,strong) NSString *param1;@property (nonatomic,strong) NSString *param2;
@end
UIButton+zz.m文件如下:
#import "UIButton+zz.h"
#import <objc/runtime.h>
static const char* ObjectTagKey1 ="ExtButtonParameter1";
static const char* ObjectTagKey2 ="ExtButtonParameter2";
@implementation UIButton (zz)
@dynamic param1;
@dynamic param2;
//扩展属性的set方法
-(void)setParam1:(NSString *)param1
{
objc_setAssociatedObject(self, ObjectTagKey1, param1, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
//扩展属性的get方法
-(NSString*)param1
{
return (NSString *)objc_getAssociatedObject(self, ObjectTagKey1);
}
//扩展属性的set方法
-(void)setParam2:(NSString *)param2
{
objc_setAssociatedObject(self, ObjectTagKey2, param2, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
//扩展属性的get方法
-(NSString*)param2
{
return (NSString *)objc_getAssociatedObject(self, ObjectTagKey2);
}
@end