by @dynamic and Objc_setassociatedobject, you can add attributes to a category, which explains: Programmers manually implement setters and getters, while the latter dynamically add properties to objects. Two mates can be used to add properties to an object.
The following code takes ScrollView as an example, adds a Refreshview property to ScrollView, and other places can use Refreshview like normal properties:
"Header File"
@interface Uiscrollview (Refresh) @property (nonatomic) refreshview * Refreshview; @end
"Source file" requires runtime header file
#import <objc/runtime.h>static Char Krefreshview, @implementation Uiscrollview (Refresh) @dynamic refreshview;-( void) Setrefreshview: (Refreshview *) Aview { objc_setassociatedobject (self, &krefreshview, Aview, OBJC_ association_retain_nonatomic);} -(Refreshview *) Refreshview { return objc_getassociatedobject (self, &krefreshview);} @end
Add attributes to categories (implemented via @dynamic and Objc_setassociatedobject)