-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathUITapImageView.m
executable file
·52 lines (42 loc) · 1.12 KB
/
UITapImageView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// UITapImageView.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-7.
// Copyright (c) 2014年 Coding. 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