.h文件
#import <UIKit/UIKit.h>
@interface UIImage (Extension)
//起始x坐标
@property(nonatomic,assign)CGFloat imageX;
//起始y轴坐标
@property(nonatomic,assign)CGFloat imageY;
@end
.m文件
#import "UIImage+Extension.h"
#import <objc/runtime.h>
static const NSString *imageXKey = @"imageX";
static const NSString *imageYKey = @"imageY";
@implementation UIImage (Extension)
- (void)setImageX:(CGFloat)imageX {
objc_setAssociatedObject(self, @selector(imageX), @(imageX), OBJC_ASSOCIATION_ASSIGN);
}
- (CGFloat)imageX {
return [(objc_getAssociatedObject(self, @selector(imageX))) doubleValue];
}
- (void)setImageY:(CGFloat)imageY {
objc_setAssociatedObject(self, &imageYKey, @(imageY), OBJC_ASSOCIATION_ASSIGN);
}
- (CGFloat)imageY {
return [(objc_getAssociatedObject(self, &imageYKey)) doubleValue];
}
@end