**************
.h文件里面
#import<UIKit/UIKit.h>
@interface UIView (Test)
@property (nonatomic,copy) NSString *name;
@end
.m文件里面
#import "UIView+Test.h"
#import<objc/runtime.h>
@implementation UIView (Test)
- (NSString *)name {
return objc_getAssociatedObject(self, @selector(name));
}
- (void)setName:(NSString *)value {
objc_setAssociatedObject(self, @selector(name),value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
**********
网友评论