//
//  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
