ClipConfirmView.m 1.57 KB
//
//  ClipConfirmView.m
//  Xingbook.Main
//
//  Created by tntjoy01 on 2018/5/25.
//

#import "ClipConfirmView.h"
#import "Masonry.h"

@interface ClipConfirmView ()

@property (strong, nonatomic) UIImageView *imageView;
@property (strong, nonatomic) UIImage *clipImage;

@end

@implementation ClipConfirmView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        if (_imageView == nil) {
            _imageView = [[UIImageView alloc]init];
        }
        [self addSubview:_imageView];
        [self setBackgroundColor:[UIColor blackColor]];
    }
    return self;
}

-(void)setImage:(UIImage *)image {
    self.clipImage = image;
    [_imageView setImage:image];
    
    if (self.frame.size.width/self.frame.size.height > image.size.width/image.size.height) {
        // 根据高度
        [_imageView mas_remakeConstraints:^(MASConstraintMaker *make){
            make.center.top.bottom.equalTo(self);
            make.width.equalTo(self.mas_height).multipliedBy(image.size.width/image.size.height);
        }];
    }else{
        // 根据宽度
        [_imageView mas_remakeConstraints:^(MASConstraintMaker *make){
            make.center.left.right.equalTo(self);
            make.height.equalTo(self.mas_width).multipliedBy(image.size.height/image.size.width);
        }];
    }
}

-(UIImage * )getClipImage {
    return self.clipImage;
}

@end