// // UITapImageView.m // zxptUser // // Created by wujunyang on 16/6/8. // Copyright © 2016年 qijia. All rights reserved. // #import "UITapImageView.h" @interface UITapImageView () @property (nonatomic, copy) void(^tapAction)(id); @end @implementation UITapImageView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } - (instancetype)init { return [self initWithFrame:CGRectZero]; } - (void)tap{ if (self.tapAction) { self.tapAction(self); } } - (void)addTapBlock:(void(^)(id obj))tapAction{ self.tapAction = tapAction; if (![self gestureRecognizers]) { self.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)]; [self addGestureRecognizer:tap]; } } -(void)setImageWithUrl:(NSURL *)imgUrl placeholderImage:(UIImage *)placeholderImage tapBlock:(void(^)(id obj))tapAction{ [self sd_setImageWithURL:imgUrl placeholderImage:placeholderImage]; [self addTapBlock:tapAction]; } @end