ClipConfirmView.m
1.57 KB
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
53
54
55
56
57
58
59
60
61
62
63
//
// 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