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
//
// GMImageView.m
// Gengmei
//
// Created by Thierry on 2/12/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import "GMImageView.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "UIView+Layout.h"
#import <Constant.h>
#import <UIColor+GMTheme.h>
@implementation GMImageView
- (instancetype)initWithImage:(nullable UIImage *)image {
self = [super initWithImage:image];
[self setup];
return self;
}
- (instancetype)initWithImage:(nullable UIImage *)image highlightedImage:(nullable UIImage *)highlightedImage {
self = [super initWithImage:image highlightedImage:highlightedImage];
[self setup];
return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
[self setup];
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
[self setup];
return self;
}
- (void)setup {
self.layer.masksToBounds = YES;
}
- (void)setImageWithUrlString:(NSString *)urlString placeHolder:(NSString *)placeHolder{
NSURL *url = [NSURL URLWithString:urlString];
if (placeHolder!=nil && ![placeHolder isEqualToString:@""]) {
[self sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:placeHolder]];
}else{
[self sd_setImageWithURL:url];
}
}
@end