1 #import<UIKit/UIKit.h>2 3typedefenum {4Hmimagedirectionleft,//left 05Hmimagedirectionright,//Right 16 } hmimagedirection;7 8 9 @interfaceUIImage (Extension)Ten //x Value One @property (nonatomic,assign) cgfloat x; A //y value - @property (nonatomic,assign) cgfloat y; - //Move Direction the @property (nonatomic,assign) hmimagedirection direction; - - @end
#import "Uiimage+extension.h"#import<objc/runtime.h>@implementationUIImage (Extension)Static CharImageX;Static CharImagey;Static Charimagedirection;- (void) SetX: (cgfloat) x{//Objc_setassociatedobject: Use this method to add attributes to a categoryObjc_setassociatedobject (self, &imagex, [NSString stringWithFormat:@"%f", X], objc_association_copy);}-(cgfloat) x {return[Objc_getassociatedobject (Self, &ImageX) Floatvalue];}- (void) Sety: (cgfloat) y {//Objc_setassociatedobject: Use this method to add attributes to a categoryObjc_setassociatedobject (self, &imagey, [NSString stringWithFormat:@"%f", y], objc_association_copy);}-(cgfloat) y {return[Objc_getassociatedobject (Self, &imagey) Floatvalue];}- (void) Setdirection: (hmimagedirection) Direction {//Objc_setassociatedobject: Use this method to add attributes to a categoryObjc_setassociatedobject (self, &imagedirection, [NSString stringWithFormat:@"%d", direction], objc_association_copy);}-(hmimagedirection) Direction {return[Objc_getassociatedobject (Self, &imagedirection) boolvalue];}@end
How to add attributes to a taxonomy