CNLiveServiceLookCell.m
4.75 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
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
//
// CNLiveServiceLookCell.m
// CNLiveCServiceModule
//
// Created by CNLive on 2021/11/27.
//
#import "CNLiveServiceLookCell.h"
#import "CNLiveCycleView.h"
@interface CNLiveServiceLookCell()
@property (nonatomic, strong) UIImageView *backImage;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subTitlelabel;
@property (nonatomic, strong) CNLiveCycleView *cycleView;
@end
@implementation CNLiveServiceLookCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self.contentView addSubview:self.backImage];
[self.backImage addSubview:self.titleLabel];
[self.backImage addSubview:self.subTitlelabel];
[self.backImage addSubview:self.cycleView];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
[self.backImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(self.contentView);
make.left.equalTo(self.contentView).offset(10);
make.right.equalTo(self.contentView).offset(-10);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backImage).offset(10);
make.top.equalTo(self.backImage).offset(15);
}];
[self.subTitlelabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLabel.mas_right).offset(10);
make.bottom.equalTo(self.titleLabel);
}];
[self.cycleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.backImage).offset(-10);
make.left.equalTo(self.backImage).offset(10);
make.right.equalTo(self.backImage).offset(-10);
make.top.equalTo(self.titleLabel.mas_bottom).offset(15);
}];
}
#pragma mark - Method
- (NSArray *)sqereList:(NSArray *)array{
NSMutableArray *dataArr = [NSMutableArray array];
NSMutableArray *sqArr = [NSMutableArray array];
for (int i = 0; i < array.count; i ++) {
NSDictionary *dic = array[i];
CnLivePageContentModel *model = [CnLivePageContentModel mj_objectWithKeyValues:dic];
[sqArr addObject:model];
if ((i != 0 || array.count == 1) && (i%2 == 0 || i == array.count - 1)) {
NSDictionary *category = @{
@"title":@"大家都在用",
@"lists":sqArr.copy,
@"layout":@{
@"width":@(self.cycleView.width),
@"height":@((self.cycleView.height - 20)/3)
}
};
CNLiveSearchHotsModel *model1 = [CNLiveSearchHotsModel mj_objectWithKeyValues:category];
[dataArr addObject:model1];
[sqArr removeAllObjects];
}
}
return dataArr.copy;
}
#pragma mark - Setting&&Getting
- (void)setModel:(CNliveServicePageModel *)model
{
_model = model;
[self.backImage sd_setImageWithURL:[NSURL URLWithString:model.background]];
NSArray *dataArr = [self sqereList:model.contents];
_cycleView.dataSource = dataArr;
_cycleView.localizationImageNamesGroup = dataArr;
self.titleLabel.text = model.blockName;
[self.titleLabel sizeToFit];
self.subTitlelabel.text = model.blockSubTitle;
[self.subTitlelabel sizeToFit];
[self setNeedsLayout];
}
- (UIImageView *)backImage
{
if (!_backImage) {
_backImage = [[UIImageView alloc] init];
_backImage.userInteractionEnabled = YES;
}
return _backImage;
}
- (UILabel *)titleLabel
{
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = UIFontMake(17);
_titleLabel.textColor = CNLiveColorWithHexString(@"#1F74E9");
_titleLabel.textAlignment = NSTextAlignmentLeft;
}
return _titleLabel;
}
- (UILabel *)subTitlelabel
{
if (!_subTitlelabel) {
_subTitlelabel = [[UILabel alloc] init];
_subTitlelabel.font = UIFontMake(12);
_subTitlelabel.textColor = CNLiveColorWithHexString(@"#1F74E9");
_subTitlelabel.textAlignment = NSTextAlignmentLeft;
}
return _subTitlelabel;
}
- (CNLiveCycleView *)cycleView
{
if (!_cycleView) {
_cycleView = [[CNLiveCycleView alloc] initWithFrame:CGRectZero];
_cycleView.layer.cornerRadius = 8;
_cycleView.backgroundColor = kWhiteColor;
_cycleView.autoScroll = NO;
_cycleView.showPageControl = YES;
_cycleView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
_cycleView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
_cycleView.hidesForSinglePage = YES;
_cycleView.currentPageDotImage = [UIImage loadBundleImage:@"pagecontrol_yes"];
_cycleView.pageDotImage = [UIImage loadBundleImage:@"pagecontrol_no"];
_cycleView.pageControlDotSize = CGSizeMake(4, 4);
}
return _cycleView;
}
@end