zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
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
//
//  PBVideoCollectionViewCell.m
//  IphoneBIMe
//
//  Created by zjf on 2020/8/25.
//  Copyright © 2020 ProBIM. All rights reserved.
//
 
#import "PBVideoCollectionViewCell.h"
@interface PBVideoCollectionViewCell()
@property (nonatomic, weak) UIImageView *imageV;
@property (nonatomic, weak) UIButton *playBtn;
@end
@implementation PBVideoCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    UIImageView *imageV = [[UIImageView alloc] init];
    [self.contentView addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(self.contentView);
    }];
//       UIViewContentModeScaleToFill,
//       UIViewContentModeScaleAspectFit,      // contents scaled to fit with fixed aspect. remainder is transparent
//       UIViewContentModeScaleAspectFill,     // contents scaled to fill with fixed aspect. some portion of content may be clipped.
//       UIViewContentModeRedraw,              // redraw on bounds change (calls -setNeedsDisplay)
//       UIViewContentModeCenter,
    imageV.contentMode = UIViewContentModeScaleAspectFill;
    imageV.backgroundColor = [UIColor blackColor];
    UIButton *playBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"details_play"]];
    [playBtn addTarget:self action:@selector(playViedo) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:playBtn];
    [playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
   
    self.imageV = imageV;
    self.playBtn = playBtn;
}
- (void)playViedo {
    if (self.PlayVideoBlock) {
        self.PlayVideoBlock();
    }
}
- (void)setVideoUrl:(NSString *)videoUrl {
    _videoUrl = videoUrl;
    NSString *imageStr = [videoUrl stringByReplacingOccurrencesOfString:@".mp4" withString:@"_image.png"];
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:imageStr] placeholderImage:[UIImage imageNamed:@""]];
}
@end