admin
2023-04-21 0b3a4aaf99ea251bc8e27b96115288f0988fcffe
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//
//  SearchDetailListCell.m
//  BuWanVideo2.0
//
//  Created by Aeline on 2020/9/19.
//  Copyright © 2020 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "SearchDetailListCell.h"
#import "UIImageView+YTH.h"
 
@interface SearchDetailListCell ()
 
@property (nonatomic, nullable, strong) UIImageView *imageViewLogo;
 
@property (nonatomic, nullable, strong) UILabel *labelTitle;
@property (nonatomic, nullable, strong) UILabel *labelTag;
@property (nonatomic, nullable, strong) UILabel *labelZY;
 
@property (nonatomic, nullable, strong) UIButton *buttonPlay;
 
@property (nonatomic, nullable, strong) UIView *viewLevel;
@end
 
@implementation SearchDetailListCell
 
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
 
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
 
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;//设置cell点击效果
        [self setupViewConfig];
    }
    return self;
}
 
- (void)setupViewConfig {
    [self.contentView addSubview:self.imageViewLogo];
    [self.contentView addSubview:self.labelTitle];
    [self.contentView addSubview:self.labelTag];
    [self.contentView addSubview:self.labelZY];
    [self.contentView addSubview:self.buttonPlay];
    [self.contentView addSubview:self.viewLevel];
}
 
- (void)setModel:(XYRVideoInfoModel *)model {
    _model = model;
    if (model) {
        [self.imageViewLogo setYthImageWithURL:model.Vpicture placeholderImage:nil];
        self.labelTitle.text = model.Name;
        self.labelTag.text = model.Tag;
        self.labelZY.text = model.MainActor;
        
        for (__strong UIView *view in [self.viewLevel subviews]) {
            [view removeFromSuperview];
            view = nil;
        }
        for (int i = 0; i < model.VideoDetailList.count; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            
            [button setTitle:[NSString stringWithFormat:@"%@",model.VideoDetailList[i][@"Tag"]] forState:UIControlStateNormal];
            if (model.VideoDetailList.count > 5) {
                if (i == 2) {
                    [button setTitle:@"..." forState:UIControlStateNormal];
                }
                
                if (i == 3) {
                    [button setTitle:[NSString stringWithFormat:@"%@",model.VideoDetailList[[model.VideoDetailList count] - 2][@"Tag"]] forState:UIControlStateNormal];
                }
                
                if (i == 4) {
                    [button setTitle:[NSString stringWithFormat:@"%@",model.VideoDetailList[[model.VideoDetailList count] - 1][@"Tag"]] forState:UIControlStateNormal];
                }
            }
           
            [button setTitleColor:UIColorFromRGBValue(0x000000) forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:12];
            button.backgroundColor = UIColorFromRGBValue(0xD3D3D3);
            button.layer.masksToBounds = YES;
            button.layer.cornerRadius = 5;
            button.tag = i;
            [self.viewLevel addSubview:button];
            CGFloat width = (KScreenW - 60) / 5;
            button.frame = CGRectMake(10 + 10 * i + width * i, 0, width, 29);
            
            [button addTarget:self action:@selector(touchIndex:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
}
 
- (void)touchIndex:(UIButton *)button {
    if (_delegate && [_delegate respondsToSelector:@selector(playVideo:)]) {
        [_delegate playVideo:_model];
    }
}
 
- (UIImageView *)imageViewLogo {
    if (!_imageViewLogo) {
        _imageViewLogo = [[UIImageView alloc] initWithFrame:CGRectMake(9, 15, 95, 131)];
        [_imageViewLogo setContentScaleFactor:[[UIScreen mainScreen] scale]];
        _imageViewLogo.contentMode = UIViewContentModeScaleAspectFill;
        _imageViewLogo.clipsToBounds = YES;
        _imageViewLogo.backgroundColor = UIColorFromRGBValue(0xf4f4f4);
    }
    return _imageViewLogo;
}
 
- (UILabel *)labelTitle {
    if (!_labelTitle) {
        _labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.imageViewLogo.frame) + 17, 16, KScreenW - 121, 15)];
        _labelTitle.textColor = UIColorFromRGBValue(0x000000);
        _labelTitle.textAlignment = NSTextAlignmentLeft;
        _labelTitle.font = [UIFont systemFontOfSize:15];
    }
    return _labelTitle;
}
 
- (UILabel *)labelTag {
    if (!_labelTag) {
        _labelTag = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.imageViewLogo.frame) + 17, CGRectGetMaxY(self.labelTitle.frame) + 7, KScreenW - 131, 15)];
        _labelTag.textColor = UIColorFromRGBValue(0xA3A3A3);
        _labelTag.textAlignment = NSTextAlignmentLeft;
        _labelTag.font = [UIFont systemFontOfSize:12];
    }
    return _labelTag;
}
 
- (UILabel *)labelZY {
    if (!_labelZY) {
        _labelZY = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.imageViewLogo.frame) + 17, CGRectGetMaxY(self.labelTag.frame) + 15, KScreenW - 131, 30)];
        _labelZY.textColor = UIColorFromRGBValue(0xA3A3A3);
        _labelZY.textAlignment = NSTextAlignmentLeft;
        _labelZY.font = [UIFont systemFontOfSize:12];
        _labelZY.lineBreakMode = NSLineBreakByTruncatingTail;
        _labelZY.numberOfLines = 2;
    }
    return _labelZY;
}
 
- (UIButton *)buttonPlay {
    if (!_buttonPlay) {
        _buttonPlay = [UIButton buttonWithType:UIButtonTypeCustom];
        _buttonPlay.frame = CGRectMake(CGRectGetMaxX(self.imageViewLogo.frame) + 17, CGRectGetMaxY(self.labelZY.frame) + 15, 109, 24);
        [_buttonPlay setTitle:@"立即播放" forState:UIControlStateNormal];
        [_buttonPlay setTitleColor:UIColorFromRGBValue(0xFFE84E) forState:UIControlStateNormal];
        _buttonPlay.titleLabel.font = [UIFont systemFontOfSize:12];
        _buttonPlay.backgroundColor = UIColorFromRGBValue(0x0051F5);
        _buttonPlay.layer.masksToBounds = YES;
        _buttonPlay.layer.cornerRadius = 12;
        [_buttonPlay addTarget:self action:@selector(touchIndex:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _buttonPlay;
}
 
- (UIView *)viewLevel {
    if (!_viewLevel) {
        _viewLevel = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.imageViewLogo.frame) + 8, KScreenW, 29)];
    }
    return _viewLevel;
}
 
- (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize {
    NSDictionary *attrs = @{NSFontAttributeName:font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}
 
@end