CNLiveShortVideoContentListView.swift
6.73 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
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
179
180
181
182
//
// CNLiveShortVideoContentListView.swift
// metaCode
//
// Created by open on 2024/1/9.
//
import Foundation
typealias CloseVideoListResultBlock = (_ videoId: Any) ->Void
class CNLiveShortVideoContentListView: UIView, UITableViewDelegate, UITableViewDataSource {
lazy var closeButton: UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "short_video_close"), for: .normal)
button.backgroundColor = .clear
button.addTarget(self, action: #selector(closeMethod), for: .touchUpInside)
return button
}()
lazy var titleLabel: UILabel = {
let label = UILabel()
label.textColor = UIColor.white
label.font = semibold_adapt_font(pointSize: 19)
label.textAlignment = .left
label.numberOfLines = 1
label.lineBreakMode = .byTruncatingTail
label.text = "爱得供养"
return label
}()
lazy var lineLabel: UILabel = {
let lineLabel = UILabel.init()
lineLabel.backgroundColor = HexColor("#686868")
return lineLabel
}()
let kVideoContentListViewCellIdentifier = "kVideoContentListViewCellIdentifier"
lazy var tableView : UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.dataSource = self
tableView.delegate = self
tableView.rowHeight = 90
tableView.estimatedRowHeight = 0
tableView.estimatedSectionFooterHeight = 0
tableView.estimatedSectionHeaderHeight = 0
tableView.backgroundColor = HexColor("#010101")
tableView.tableFooterView = UIView.init()
tableView.separatorStyle = .none
tableView.scrollsToTop = false
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: get_system_tabbar_ui_offsetHeight(), right: 0)
tableView.contentInsetAdjustmentBehavior = .never;
tableView.register(CNLiveShortVideoContentListTableViewCell.self, forCellReuseIdentifier: kVideoContentListViewCellIdentifier)
return tableView
}()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(closeButton)
closeButton.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-15)
make.top.equalToSuperview().offset(15)
make.size.equalTo(30)
}
addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.top.left.equalToSuperview().offset(20)
make.right.equalTo(closeButton.snp.left).offset(-10)
}
addSubview(lineLabel)
lineLabel.snp.makeConstraints { make in
make.top.equalTo(closeButton.snp.bottom).offset(15)
make.centerX.equalToSuperview()
make.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.height.equalTo(1)
}
addSubview(tableView)
tableView.snp.makeConstraints { make in
make.bottom.left.right.equalToSuperview()
make.top.equalTo(lineLabel.snp.bottom).offset(10)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc func closeMethod() {
removeFromSuperview()
}
static public func showVideoContentListView(result: @escaping CloseVideoListResultBlock) {
let pickerView = CNLiveShortVideoContentListView.init(frame: CGRect.zero)
pickerView.backgroundColor = HexColor("#010101")
let delegate = UIApplication.shared.delegate as! AppDelegate
delegate.window?.addSubview(pickerView)
pickerView.snp.makeConstraints { make in
make.top.equalTo(250)
make.right.left.bottom.equalToSuperview()
}
delegate.window?.layoutIfNeeded()
pickerView.alpha = 0
UIView.animate(withDuration: 0.1) {
pickerView.alpha = 1
} completion: { _ in}
}
}
extension CNLiveShortVideoContentListView {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: kVideoContentListViewCellIdentifier) as? CNLiveShortVideoContentListTableViewCell else {
return CNLiveShortVideoContentListTableViewCell()
}
return cell
}
}
class CNLiveShortVideoContentListTableViewCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.backgroundColor = .clear
backgroundColor = .clear
selectionStyle = .none
let imageView = UIImageView.init()
imageView.image = UIImage(named: "mine_auth_result_header_failer")
imageView.contentMode = .scaleAspectFill
imageView.layer.cornerRadius = 5
imageView.layer.masksToBounds = true
imageView.clipsToBounds = true
contentView.addSubview(imageView)
imageView.snp.makeConstraints { make in
make.left.top.equalToSuperview().offset(20)
make.width.equalTo(50)
make.height.equalTo(70)
}
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 6
let titleLabel = UILabel.init()
titleLabel.attributedText = NSAttributedString(string: "第四集 我们都不知道,所做的哪一个选择会让命运的齿轮开始转动", attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
titleLabel.textColor = .white
titleLabel.lineBreakMode = .byTruncatingTail
titleLabel.numberOfLines = 2
titleLabel.font = medium_adapt_font(pointSize: 12)
contentView.addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.left.equalTo(imageView.snp.right).offset(10)
make.top.equalToSuperview().offset(20)
make.right.equalToSuperview().offset(-20)
}
let timeLabel = UILabel.init()
timeLabel.text = "04:45"
timeLabel.textColor = .white
timeLabel.font = light_adapt_font(pointSize: 13)
contentView.addSubview(timeLabel)
timeLabel.snp.makeConstraints { make in
make.left.equalTo(imageView.snp.right).offset(10)
make.bottom.equalTo(imageView.snp.bottom)
make.right.equalToSuperview().offset(-20)
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}